Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question About Classpath and Packages

 
Russ Russell
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Russ Russell
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic