• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Question About Classpath and Packages

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic