File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Setting classpath and compiling HELP! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Setting classpath and compiling HELP!" Watch "Setting classpath and compiling HELP!" New topic
Author

Setting classpath and compiling HELP!

Larry Xu
Greenhorn

Joined: Sep 19, 2005
Posts: 11
Hi all, I am having trouble compiling the following:

2 directories: dir1, dir2. Both under the same parent directory parentDir

2 jar files in dir1 named A.jar and B.jar

a file in dir2 that's named HelloWorld.java that uses classes in the 2 jars described above

in order to compile HelloWorld.java correctly, how would I set up the classpath correctly so the compiler knows where to find the classes used in HelloWorld.java.

so far i tried this: javac -classpath dir1/A.jar dir1/B.jar dir2/HelloWorld.java (didn't work)


really appreciate your help.


I am so frustrated...
Suresh Naidu
Greenhorn

Joined: Jun 23, 2005
Posts: 13
This might be useful to you
http://www.surfscranton.com/architecture/JavaEnvironment.htm
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
What does (didn't work) mean exactly? Were there error messages? What were the error messages? etc

Try running the javac command from the same directory that the source file is in. Adjust the classpath to the jar files accordingly.

javac -classpath <prgm>.java
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
Whoops left out the classpath: no blanks and ; between
javac -classpath <path1>;<path2> <pgm>.java
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This Sun page http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html is a good start even before mine on SurfScranton. Having any luck yet?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Larry Xu
Greenhorn

Joined: Sep 19, 2005
Posts: 11
thanks for all the help, it's working now. One more question, so if i have alot of jar files should i move them into lib directory and permanently set my classpath there? or is there a better way of doing this.

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I find it handy to keep my own things in a lib directory and third party jars in a subdirectory of that. Some environments like WebSphere require or recommend specific setups that vary from that.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8829
    
    5
Stan -

There are only two kinds of programming languages: those people always bitch about and those nobody uses. Bjarne Stroustru


Is that a real quote?

ROFL


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting classpath and compiling HELP!