using the jre/lib/ext directory and your own directory

I usually do not use the $JAVA_HOME/jre/lib/ext directory for 3rd party jars, preferring instead to specify jars via a carefully controlled CLASSPATH. But ...

I'm using a 3rd party API, writing my own classes on top of it. I place the 3rd party jar in

the $JAVA_HOME/jre/lib/ext directory, and keep my classes in another directory. I set my classpath

to include the top level directory where my classes can be found. Everything compiles fiine.

When I go to run, I keep my CLASSPATH setting, but I get ClassNotFoundExceptions from the JVM when it tries to load my classes. It find the 3rd party classes just fine, but cannot find mine.

When I jar up my classes and put that jar in the $JAVA_HOME/jre/lib/ext directory and unset my classpath, everything compiles AND runs.

When I move the 3rd Party jar to another directory and set my classpath to include the 3rd party directory and my directory, everything comiples and runs.

So, the question is, if you insist on putting your jars into $JAVA_HOME/jre/lib/ext, must you then put all code there? Is this a security issue?

[1127 byte] By [jeffmathis] at [2007-9-26 3:58:55]
# 1
It's an embarrassment, and we uncovered it too. Java seems to not have much of a concept of "search path".
bschauwe at 2007-6-29 12:52:20 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

I found the issue:

It all has to do with ClassLoader heirarchy.

If a call to Class.forName(someClassString) is called by a class from with the ext directory, it will only look for that class IN the ext directory.

So, my workaround was to subclass/rewrite all the classes in my 3rd party jar that performed dynamic loading. I can see the security issues involved here, and in retrospect I'd agree with the behavior.

Moral: don't use the ext directory unless you know what your classes are doing

jeffmathis at 2007-6-29 12:52:20 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
Could you please explain in more detail:When you rewrote the 3rd party jars,- did you then put them in lib/ext?- what did you actually change?- where did you put your code?thanks,Markus
remarkus at 2007-6-29 12:52:20 > top of Java-index,Java HotSpot Virtual Machine,Specifications...