File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes Question About Classpath and Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Question About Classpath and Packages" Watch "Question About Classpath and Packages" New topic
Author

Question About Classpath and Packages

Russ Russell
Ranch Hand

Joined: Jan 24, 2010
Posts: 72
Hi -

I have a directory on my HD where I'd like to keep all of my self-created reuslable classes for import into other projects. The directory is: C:\JavaCode\ReusableClasses.

I tried putting C:\JavaCode\ReusableClasses in my classpath. I did this in Windows by selecting My Computer > Properties > Advanced > Environment Varables > Classpath.

However, every time I attempt to import a class from that directory into a new project, Eclipse complains that It can't resolve it. Eclipse then suggests to include the "ReusableClasses" project in the build of my current project. This works, but I'd like to simply be able to import my custom classes without this extra step. What am I doing wrong?

Thanks in advance,
-Russ
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Environment Varables > Classpath

This environement variable is case sensitive. It is CLASSPATH, not Classpath.

Eclipse complains that It can't resolve it.

I don't think that Eclipse uses the Windows CLASSPATH variable. Right-click your project, click "Properties". Go to "Java Build Path/Libraries", click "Add external class folder". Select "C:\JavaCode\ReusableClasses" and click ok.

(If you really want them to be reusable, I think it would be better to package them in a JAR file)

[My Blog]
All roads lead to JavaRanch
Russ Russell
Ranch Hand

Joined: Jan 24, 2010
Posts: 72
Thanks for the reply. I followed your instructions, and all seems fine except for this compuiler warning:

The following classpath entry 'C:\JavaCode\ReusableClasses' will not be available on the server's classpath

What are the implications of this?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What are the implications of this?

I think that putting classes in a local directory like this does not make them reusable. Especially if you are making a web application. You'd better make a jar file, and import the jar file in your project.
Russ Russell
Ranch Hand

Joined: Jan 24, 2010
Posts: 72
I hate to sould like a TOTAL greenhorn, but how do I make a jar file? Can I do this using Eclipse, or do I need another utility?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Russ Russell wrote:Can I do this using Eclipse


Yes. right click on the folder which has the reusable classes and Export----> jar
Russ Russell
Ranch Hand

Joined: Jan 24, 2010
Posts: 72
Thank you very much. So I just export this to a directory on my hard drive and then I can import the Jar via Project > Properties > Java Build Path/Libraries > Add external JARs?

Then, later, can I add classes to this JAR the same way?

Thanks again for all your help.

 
wood burning stoves
 
subject: Question About Classpath and Packages
 
Similar Threads
Buildpath problem with Eclipse
import and package... ?
Error compiling a simple servlet !!.... any ideas??
CLASSPATH Environment Variable
Using Eclipse for Web App