Dear Johnny and all,
thanks for the hint, that's was the problem (File to URL conversion, I mean). In fact I built URL object from string and so I had a mix between slash and backslash style, (something like "file://C:\Program Files\...")... now I build a File and then I get the URL from it doing a .toURI().toURL() and all works fine.

Thanks again,
Andrea Del Linz

Johnny Kewl wrote:

---------------------------------------------------------------------------
HARBOR: http://coolharbor.100free.com/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
--------------------------------------------------------------------------- ----- Original Message ----- From: "Andrea Del Linz" <[EMAIL PROTECTED]>
To: <users@tomcat.apache.org>
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 class.

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: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to