Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAR Files and CLASSPATH Problem

 
Aniah Ushie
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy fellas! I'm working on a project that requires me use some API's (which are zipped Jar files). The vendors gave their instructions:
(a) Unzip the Zip file (I ravished that with Winzip)
*(b) The resulting (unzipped) directory has 3 directories among which is the lib directory, add all the .jar in the lib directory to ur Classpath. I did so thru the Enviroment Variable in Windows.

The problem now is that the example code which I am supposed to test doesnt compile. It imports some packages and classes which I can only see if I extract the Jars (ie jar xf jarFile). These imported classes and packages and their member functions are what javac complains about. I believe there's something I'm not doing right. I'll need someone to give me a detailed approach to using jar files in a program, thanks.
 
Pratik Lohia
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you add it to the classpath using envirinment variables?
1. Specified each jar seperately OR
2. Just added the path upto the lib directory?

The second method would be the more appropriate way to do. But watever you do remember to append the ";" to the end of the path, otherwise the CLASSPATH will not pick up the last path mentioned.

Hope that helps!!!
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But watever you do remember to append the ";" to the end of the path, otherwise the CLASSPATH will not pick up the last path mentioned.
--------------------------

Are you sure this is correct. Different jar files should be separated by a ";" but I think it is not required for the last one. Try to add your present directory to the CLASSPATH too. like set CLASSPATH=%CLASSPATH%;.\

The best method I think would be to create a CLASSPATH variable in the Environment variables and add .jar files to it. check to see whether they are in the classpath from the command prompt by typing "set classpath". When you add something include %CLASSPATH% so that earlier set classpath would still exist. One other way would be to have a small batch script which would set your classpath as required for your application. You can run it when its required instead of setting it in Environmental variables.

Hope this makes sense to you.

Cheers
Chandu
----------
SCJP 1.4
SCWCD(preparing)
 
adithya kallu
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think even simpler would be take all the jar files and put it in web-inf/lib
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pratik Lohia:
How did you add it to the classpath using envirinment variables?
2. Just added the path upto the lib directory?

The second method would be the more appropriate way to do.

I think this won't work. As far as I know, you still need to add each individual jar file to your classpath.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Java in General (beginner).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic