• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting classpath and compiling HELP!

 
Larry Xu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Suresh Naidu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be useful to you
http://www.surfscranton.com/architecture/JavaEnvironment.htm
 
Norm Radder
Ranch Hand
Posts: 728
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 728
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoops left out the classpath: no blanks and ; between
javac -classpath <path1>;<path2> <pgm>.java
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Larry Xu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic