tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johnny Kewl" <>
Subject Re: URLClassLoader and Reflection fail on Windows.
Date Wed, 14 May 2008 23:40:38 GMT

The most powerful application server on earth.
The only real POJO Application Server.
----- Original Message ----- 
From: "Andrea Del Linz" <>
To: <>
Sent: Tuesday, May 13, 2008 4:23 PM
Subject: URLClassLoader and Reflection fail on Windows.

> Dear All,
> I have developed a webapp that loads dynamically java classes from jar
> files. Practically you put a jar file in a specified directory and the
> application will try to load a specified class from it. The application
> works with tomcat on Unix systems (both Linux and MacOSX) but it doesn't
> work on Windows system. I've tried to execute the code outside tomcat as
> standalone application and it works under Windows too.
> To load jars I create an instance of URLClassLoader with the jar url as
> first argument and getClass().getClassLoader() as second argument (the
> parent class loader).
> I catch the java.lang.ClassNotFoundException when I use my instance of
> URLClassLoader to load dynamically the class. I think that is a parent
> class loader problem, because it's the only difference between
> standalone and webapp runnings. Could someone help me to resolve that?
> Thanks in advance,
> Andrea Del Linz

Andrea its always easier to follow with the snippet of code and the actual 
error message...
Class loaders are extremely tricky things...
The question I have is, the class that is not found, is it one of the 
classes in the JAR?

If not, then you right, when you run it outside... the parent class loader 
can see that external class.
But when you run it in the webapp, the TC class loaders cannot see that 

And you have to be so careful when testing as well, if you have classpaths 
set up in the environment for example, and you happen to have test JARs all 
over the machine... then your URL class loader may not even be getting it... 
but it still seems to work.
Theres a whole delegation thing going on... so for example, you have the 
URLs screwed up in the code, you run it outside, and it works because the 
parent classloader is finding it... but inside TC, the parent class loader 
cannot find it, but the code is screwed, and now we all looking in the wrong 
place for the problem ;)

Post the code... then this magic mailing list will start working for you ;)
My guess... probably the conversion of file to url is suspect ;) 

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message