Click to See Complete Forum and Search --> : Java Jar and CLASSPATH Problem


goon12
04-26-2007, 01:32 PM
Hi,
I am having a very annoying problem right now. First, this all happened when I tried to use Netbeans 5.5 and it was throwing an error. Going by what a Netbeans developer recommended it was because of a jar file existing in my WEB-INF/lib folder as well as my JAVA_HOME/jre/lib/ext folder. It was only in the jre/lib/ext folder. The reason it was in the jre/lib/ext folder is because that is the only place I could use that jar file.
Here are the commands I used to do this.

$ echo $CLASSPATH
/usr/local/classes
// foo folder contains some classes in "package foo;"
$ jar -cf foo.jar foo/
$ mv foo.jar /u
$ vim TestClass.java
// TestClass imports foo "import foo.*;"
$ javac TestClass.java
( errors because it can't find the classes from foo.jar )
$ javac TestClass.java -cp /usr/local/classes/foo.jar
$ mv TestClass.class /usr/local/classes
$ java TestClass
( Error complaining that it can't load a class from foo.jar )
$ su
# mv /usr/local/classes/foo.jar $JAVA_HOME/jre/lib/ext
# exit
$ java TestClass
Program output.


Where is the correct place to put custom jar files, since CLASSPATH doesn't seem to be working?

Again, I can put this jar file in WEB-INF/lib folder of a JSP/Servlet application and it loads fine.

Thanks,
goon12

goon12
04-26-2007, 02:05 PM
Just an update: I

If I change my CLASSPATH, in my .bashrc file, to read:

CLASSPATH = /usr/local/classes:/usr/local/classes/foo.jar

The test application will run. However, that doesn't seem like a very good/flexible solution though.