tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fabien Benoit <fabien.ben...@gmail.com>
Subject playing outside the tomcat 4 classloaders "sandbox"
Date Tue, 23 Aug 2005 14:36:02 GMT
Hi everyone.

I'm using Tomcat (4.1) and Axis 1.2 to provide a web service interface
to a classical 2-tier application. My problem is, I need to access the
existing API of this application, a single jar located outside the
tomcat install. Copying this jar inside tomcat commmon lib dir or
webapp lib dir is not permitted.
Since tomcat gets rid of the system classpath, my first thought was to
use a custom classloader, making the WebAppClassLoader his parent, and
then set the context class loader with this new classloader :
Thread.currentThread().setContextClassLoader(myClassLoader);

But it doesn't work. The myClassLoader.loadClass("JarUrl") works fine
but I still have a NoClassDefFoundError when I try to use directly a
class from the jar.
Here is the code :

URLClassLoader classloader = new URLClassLoader(
    new URL[] { new URL(classpath)} , 
    Thread.currentThread().getContextClassLoader() 
);
Thread.currentThread().setContextClassLoader(classloader);

classloader.loadClass("mc.mis.batch.BatchParams");  => ok, returns the
good Class object

mc.mis.batch.BatchParams batchParam = new mc.mis.batch.BatchParams();
=> NoClassDefFoundError 

If someone has an other idea, or know what is wrong, I would thank him forever.
Fabien

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message