You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Albert Greinoecker <al...@uibk.ac.at> on 2007/10/10 14:42:26 UTC

Classloader - WEB-INF/lib

Hi,

I have a problem concerning the classloader tomcat is using, When I try
to load a class dynamically, which is located witihn a jar-archive
under /WEB-INF/lib with class.forName(<full_class_name>), an exception
is thrown. If the class is located at WEB-INF/classes, everything works
fine.

As classloader I am using:
Thread.currentThread().getContextClassLoader(); Should I use a different
one? What would be the best approach to solve this?

thx,
Albert


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


Re: Classloader - WEB-INF/lib

Posted by David Smith <dn...@cornell.edu>.
Can you post the actual relevant lines of code?  Also, I suspect for 
classes, Class.forName() is enough -- no need to find the class first w/ 
Classloader.getResource( "..." ).

--David

Albert Greinoecker wrote:

>I'm sorry I just found out that the cause of the failure described below
>lies one step before the class.forName-statement.
>
>Before I'm trying to load the classes with 
>ClassLoader cld [...]
>URL resource = cld.getResource('path/to/the/class/file.class');
>so it's clear to me that this cannot work with class-files located
>within a java-archive. But how can resources be loaded from jars this
>way?
>
>sorry for the last posting,
>Albert
>
>Am Mittwoch, den 10.10.2007, 08:59 -0400 schrieb David Smith:
>  
>
>>Could you post more info -- e.g. tomcat version, jvm version, class 
>>package and name you are trying to load, any relevant stack traces in 
>>the logs, etc., ...
>>
>>--David
>>
>>Albert Greinoecker wrote:
>>
>>    
>>
>>>Hi,
>>>
>>>I have a problem concerning the classloader tomcat is using, When I try
>>>to load a class dynamically, which is located witihn a jar-archive
>>>under /WEB-INF/lib with class.forName(<full_class_name>), an exception
>>>is thrown. If the class is located at WEB-INF/classes, everything works
>>>fine.
>>>
>>>As classloader I am using:
>>>Thread.currentThread().getContextClassLoader(); Should I use a different
>>>one? What would be the best approach to solve this?
>>>
>>>thx,
>>>Albert
>>>
>>>
>>>---------------------------------------------------------------------
>>>To start a new topic, e-mail: users@tomcat.apache.org
>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>> 
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To start a new topic, e-mail: users@tomcat.apache.org
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>  
>


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


RE: Classloader - WEB-INF/lib

Posted by Martin Gainty <mg...@hotmail.com>.
Hi AlbertWhich classloader you want depends on where you loaded your jarTake a look at 
http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
 
HTH/Martin Gainty______________________________________________Disclaimer and confidentiality noteEverything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.> > I'm sorry I just found out that the cause of the failure described below> lies one step before the class.forName-statement.> > Before I'm trying to load the classes with > ClassLoader cld [...]> URL resource = cld.getResource('path/to/the/class/file.class');> so it's clear to me that this cannot work with class-files located> within a java-archive. But how can resources be loaded from jars this> way?> > sorry for the last posting,> Albert> > Am Mittwoch, den 10.10.2007, 08:59 -0400 schrieb David Smith:> > Could you post more info -- e.g. tomcat version, jvm version, class > > package and name you are trying to load, any relevant stack traces in > > the logs, etc., ...> > > > --David> > > > Albert Greinoecker wrote:> > > > >Hi,> > >> > >I have a problem concerning the classloader tomcat is using, When I try> > >to load a class dynamically, which is located witihn a jar-archive> > >under /WEB-INF/lib with class.forName(<full_class_name>), an exception> > >is thrown. If the class is located at WEB-INF/classes, everything works> > >fine.> > >> > >As classloader I am using:> > >Thread.currentThread().getContextClassLoader(); Should I use a different> > >one? What would be the best approach to solve this?> > >> > >thx,> > >Albert> > >> > >> > >---------------------------------------------------------------------> > >To start a new topic, e-mail: users@tomcat.apache.org> > >To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org> > >For additional commands, e-mail: users-help@tomcat.apache.org> > >> > > > > >> > > > > > ---------------------------------------------------------------------> > To start a new topic, e-mail: users@tomcat.apache.org> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org> > For additional commands, e-mail: users-help@tomcat.apache.org> > > > > ---------------------------------------------------------------------> To start a new topic, e-mail: users@tomcat.apache.org> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org> For additional commands, e-mail: users-help@tomcat.apache.org> 
_________________________________________________________________
Help yourself to FREE treats served up daily at the Messenger Café. Stop by today.
http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_OctWLtagline

Re: Classloader - WEB-INF/lib

Posted by Albert Greinoecker <al...@uibk.ac.at>.
I'm sorry I just found out that the cause of the failure described below
lies one step before the class.forName-statement.

Before I'm trying to load the classes with 
ClassLoader cld [...]
URL resource = cld.getResource('path/to/the/class/file.class');
so it's clear to me that this cannot work with class-files located
within a java-archive. But how can resources be loaded from jars this
way?

sorry for the last posting,
Albert

Am Mittwoch, den 10.10.2007, 08:59 -0400 schrieb David Smith:
> Could you post more info -- e.g. tomcat version, jvm version, class 
> package and name you are trying to load, any relevant stack traces in 
> the logs, etc., ...
> 
> --David
> 
> Albert Greinoecker wrote:
> 
> >Hi,
> >
> >I have a problem concerning the classloader tomcat is using, When I try
> >to load a class dynamically, which is located witihn a jar-archive
> >under /WEB-INF/lib with class.forName(<full_class_name>), an exception
> >is thrown. If the class is located at WEB-INF/classes, everything works
> >fine.
> >
> >As classloader I am using:
> >Thread.currentThread().getContextClassLoader(); Should I use a different
> >one? What would be the best approach to solve this?
> >
> >thx,
> >Albert
> >
> >
> >---------------------------------------------------------------------
> >To start a new topic, e-mail: users@tomcat.apache.org
> >To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >  
> >
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


Re: Classloader - WEB-INF/lib

Posted by David Smith <dn...@cornell.edu>.
Could you post more info -- e.g. tomcat version, jvm version, class 
package and name you are trying to load, any relevant stack traces in 
the logs, etc., ...

--David

Albert Greinoecker wrote:

>Hi,
>
>I have a problem concerning the classloader tomcat is using, When I try
>to load a class dynamically, which is located witihn a jar-archive
>under /WEB-INF/lib with class.forName(<full_class_name>), an exception
>is thrown. If the class is located at WEB-INF/classes, everything works
>fine.
>
>As classloader I am using:
>Thread.currentThread().getContextClassLoader(); Should I use a different
>one? What would be the best approach to solve this?
>
>thx,
>Albert
>
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>  
>


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