Frequently Used Classes

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2009
Posts: 28
Reputation: bruceaj is an unknown quantity at this point 
Solved Threads: 0
bruceaj bruceaj is offline Offline
Light Poster

Frequently Used Classes

 
0
  #1
Oct 18th, 2009
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..
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,657
Reputation: BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold BestJewSinceJC is a splendid one to behold 
Solved Threads: 206
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
0
  #2
Oct 18th, 2009
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.*;
Out.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
1
  #3
Oct 19th, 2009
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1,030
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 153
JamesCherrill JamesCherrill is offline Offline
Veteran Poster
 
0
  #4
Oct 19th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 28
Reputation: bruceaj is an unknown quantity at this point 
Solved Threads: 0
bruceaj bruceaj is offline Offline
Light Poster
 
0
  #5
Oct 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 54
quuba quuba is offline Offline
Posting Whiz
 
0
  #6
Oct 20th, 2009
Project
Properties
Libraries
Add JAR/Folder
find folder and indicate your jar file
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 28
Reputation: bruceaj is an unknown quantity at this point 
Solved Threads: 0
bruceaj bruceaj is offline Offline
Light Poster
 
0
  #7
Oct 20th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 54
quuba quuba is offline Offline
Posting Whiz
 
0
  #8
Oct 20th, 2009
Modify build.xml file, look at files inside nbproject folder.
go to http://www.netbeans.org/ for info.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 311 | Replies: 7
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC