You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Clemens Eisserer <li...@gmail.com> on 2011/06/06 23:47:25 UTC

Class.forName doesn't find classes located in WEB-INF/lib

Hi,

I have a servlet which dynamically loads classes from jar-files
located in WEB-INF/lib/,
however tomcat somehow seems to ignore those jar-files.

in WEB-INF/lib/Notepad.jar there is a class Notepad.class (without any package),
however loading that class yields:

Loading Application Class: Notepad
java.lang.ClassNotFoundException: Notepad
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:186)
	at net.java.openjdk.cacio.servlet.AppStarter.doGet(Unknown Source)


Any idea what could be the problem here?
Does tomcat use some kind of security manager which is blocking class-loading?

Thank you in advance, Clemens

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


RE: Class.forName doesn't find classes located in WEB-INF/lib

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Clemens Eisserer [mailto:linuxhippy@gmail.com] 
> Subject: Class.forName doesn't find classes located in WEB-INF/lib

> I have a servlet which dynamically loads classes from jar-files
> located in WEB-INF/lib/,

Do you do your own classloading, or let Tomcat's classloaders do it?  If the former, why?

> Loading Application Class: Notepad
> java.lang.ClassNotFoundException: Notepad
>	at java.lang.Class.forName0(Native Method)
>	at java.lang.Class.forName(Class.java:186)
>	at net.java.openjdk.cacio.servlet.AppStarter.doGet(Unknown Source)

So what's going on inside your net.java.openjdk.cacio.servlet.AppStarter class?  What is the current classloader set to?

> Any idea what could be the problem here?

Make sure you don't have Notepad.class in more than one place.

> Does tomcat use some kind of security manager which is blocking 
> class-loading?

Maybe.  (You might get a more definitive answer if you supplied more definitive information, such as the Tomcat version you're using, where you got it from, and how you're starting it.  If it didn't come from tomcat.apache.org, all bets are off.)

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


Re: Class.forName doesn't find classes located in WEB-INF/lib

Posted by Mark Thomas <ma...@apache.org>.
On 06/06/2011 23:35, Clemens Eisserer wrote:
> Hi Martin,
> 
>> 3)webapp (everything found in WEB-INF/lib and WEB-INF/classes)
>>
>> you are using system classloader to loaf WEB-INF/lib jar
>> use the webapp classloader
> 
> So according to this, the servlet as well as the classes from
> WEB-INF/lib are loaded with the same classloader?
> What I did in the servlet was basically: this.getClass().forName("Notepad");
> 
> I've now changed the code to (where this refers to the Servlet):
> ClassLoader loader = this.getClass().getClassLoader();
> Class cls = loader.loadClass(className);
> 
> However loader in this case is null, any idea what is going on?

http://marc.info/?t=104265576200003&r=1&w=2
(which is linked from the Class Not Found FAQ which I'm guessing you
didn't read).

Mark

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


Re: Class.forName doesn't find classes located in WEB-INF/lib

Posted by Clemens Eisserer <li...@gmail.com>.
Hi Martin,

> 3)webapp (everything found in WEB-INF/lib and WEB-INF/classes)
>
> you are using system classloader to loaf WEB-INF/lib jar
> use the webapp classloader

So according to this, the servlet as well as the classes from
WEB-INF/lib are loaded with the same classloader?
What I did in the servlet was basically: this.getClass().forName("Notepad");

I've now changed the code to (where this refers to the Servlet):
ClassLoader loader = this.getClass().getClassLoader();
Class cls = loader.loadClass(className);

However loader in this case is null, any idea what is going on?

Thank you in advance, Clemens



>
> ClassLoader webinf_loader=AClassInWebINFLib.getClass().getClassLoader();
> boolean initialize=true;
> static Class<?> clazz= java.lang.Class.forName(YourClassName,
> initialize,
> webinf_loader)
>
>
> Martin
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
> Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
> dient lediglich dem Austausch von Informationen und entfaltet keine
> rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
> E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
>
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le
> destinataire prévu, nous te demandons avec bonté que pour satisfaire
> informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie
> de ceci est interdite. Ce message sert à l'information seulement et n'aura
> pas n'importe quel effet légalement obligatoire. Étant donné que les email
> peuvent facilement être sujets à la manipulation, nous ne pouvons accepter
> aucune responsabilité pour le contenu fourni.
>
>
>
>
>> Date: Mon, 6 Jun 2011 23:47:25 +0200
>> Subject: Class.forName doesn't find classes located in WEB-INF/lib
>> From: linuxhippy@gmail.com
>> To: users@tomcat.apache.org
>>
>> Hi,
>>
>> I have a servlet which dynamically loads classes from jar-files
>> located in WEB-INF/lib/,
>> however tomcat somehow seems to ignore those jar-files.
>>
>> in WEB-INF/lib/Notepad.jar there is a class Notepad.class (without any
>> package),
>> however loading that class yields:
>>
>> Loading Application Class: Notepad
>> java.lang.ClassNotFoundException: Notepad
>> at java.lang.Class.forName0(Native Method)
>> at java.lang.Class.forName(Class.java:186)
>> at net.java.openjdk.cacio.servlet.AppStarter.doGet(Unknown Source)
>>
>>
>> Any idea what could be the problem here?
>> Does tomcat use some kind of security manager which is blocking
>> class-loading?
>>
>> Thank you in advance, Clemens
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>

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