944,131 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 570
  • Java RSS
Oct 18th, 2009
0

Frequently Used Classes

Expand Post »
I have several classes that I use in almost every one of my projects. What, and How, do I create something so the I can easily access them?

I'm use NetBeans for my IDE.

Thanks..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
bruceaj is offline Offline
28 posts
since Sep 2009
Oct 18th, 2009
0
Re: Frequently Used Classes
You can use a package that includes all of your essential classes and just import that package into any class where you want to use those classes. So basically, if you wanted to import the popular File class, you would use import java.io.File; but if you wanted to import the whole package you could say import java.io.*;
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Oct 19th, 2009
1
Re: Frequently Used Classes
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Oct 19th, 2009
0
Re: Frequently Used Classes
Assuming these are your classes (not just ones in the Java API) put them all in a jar. Netbeans has a tool for creating one.
Featured Poster
Reputation Points: 1938
Solved Threads: 953
Posting Expert
JamesCherrill is offline Offline
5,809 posts
since Apr 2008
Oct 20th, 2009
0
Re: Frequently Used Classes
I've tried but failed to create a file of common classes that I can import! Here's what I did.
I'm using NetBeans 6.7.1 as my IDE.

1) I created standard Project:
File -> Java:Java Application -> Project Name: common.Code. I Left Create Main Class and Set as Main Project both checked. This created a package named "commoncode" with a main class of CommonCode.

2) I then added a file containing one of the classes I want use as common code.

3) I did a Clean and Build project.

4) In the output, the path for the jar was was listed. I copied the absolute path,including the jar file name, to my CLASSPATH.

5) I restarted NetBeans.

6) I then tried all these imports. None worked.
import common.Code.*;
import CommonCode.*;
import commoncode.*;

So, my friends, what am I doing wrong?

Thanks you very much for your help.
Last edited by bruceaj; Oct 20th, 2009 at 4:06 pm. Reason: technical errors
Reputation Points: 10
Solved Threads: 0
Light Poster
bruceaj is offline Offline
28 posts
since Sep 2009
Oct 20th, 2009
0
Re: Frequently Used Classes
Quote ...
Project
Properties
Libraries
Add JAR/Folder
find folder and indicate your jar file
Reputation Points: 123
Solved Threads: 106
Posting Pro
quuba is offline Offline
573 posts
since Nov 2008
Oct 20th, 2009
0
Re: Frequently Used Classes
Thanks. Adding it to the project classpath worked. The thing I don't like is that it looks like I have to manually add it to the classpath of each project I build. How can I have it added automatically?

Also, can I remove it from my System Classpath?
Last edited by bruceaj; Oct 20th, 2009 at 6:11 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
bruceaj is offline Offline
28 posts
since Sep 2009
Oct 20th, 2009
0
Re: Frequently Used Classes
Modify build.xml file, look at files inside nbproject folder.
go to http://www.netbeans.org/ for info.
Reputation Points: 123
Solved Threads: 106
Posting Pro
quuba is offline Offline
573 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Have you ever felt this dumb? (It's SO not fun.)
Next Thread in Java Forum Timeline: Linked List program - stumped w/ 1 problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC