You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steven Nakhla <sd...@gmail.com> on 2005/11/04 02:09:26 UTC

Load class from different web app

I'm writing a web application (a portal app, to be specific) that needs to
be able to load a class (using Class.forName(...)) that was deployed in a
different web application from the one I am developing. I've deployed the
target web app containing the class I want to load, but whenever I call
Class.forName(), I get a "java.lang.ClassNotFoundException". Is there
anything special I need to do if I want to load this class? It appears it is
a classloader issue, but I don't know enough to determine what the problem
is. Any help is greatly appreciated!

Steve Nakhla

RE: Load class from different web app

Posted by Michael Forster <mp...@muckworld.com>.
Well for the JNI it was necessary as it is like a dll in windows and cannot
be loaded more than once - which Tomcat would try to do - 1 for each
instance.

Mike.

-----Original Message-----
From: Tim Funk [mailto:funkman@joedog.org]
Sent: 04 November 2005 12:40
To: Tomcat Users List
Subject: Re: Load class from different web app


Placing classes jdk/jre/lib/ext puts them into the system classloader. This
opens a whole class of class not found errors and errors related to tomcat
not reloading classes. (As well as memory leaks due to Classloaders not
being
freed)

-Tim

Michael Forster wrote:

> That is not strictly true, We had an application at work that used JNI and
> was part of a Database access library as well as accessing things like the
> Machines Hostmac address.
>
> We could not run it from the Tomcat area and had to put it into a jar file
> and put the jar file into the JVM jdk/jre/lib/ext dir and then it worked
> fine as any classes / libraries in that dir are loaded by the JVM meaning
> they are always available - This is also where we put the JDBC driver jar.
>
> Mike.
>
> -----Original Message-----
> From: Tim Funk [mailto:funkman@joedog.org]
> Sent: 04 November 2005 11:32
> To: Tomcat Users List
> Subject: Re: Load class from different web app
>
>
> You are violating the servlet spec. Do not pass go, do not collect $200.
>
> Classes for a webapp need to be in WEB-INF/classes and WEB-INF/lib. Tomcat
> does allow for webapps to share classes via the $CATALINA_HOME/shared and
> $CATALINA_HOME/common directories but you'll need to see the classloader
> docs
> on any restrictions.
>
> -Tim
>
> Steven Nakhla wrote:
>
>
>>I'm writing a web application (a portal app, to be specific) that needs to
>>be able to load a class (using Class.forName(...)) that was deployed in a
>>different web application from the one I am developing. I've deployed the
>>target web app containing the class I want to load, but whenever I call
>>Class.forName(), I get a "java.lang.ClassNotFoundException". Is there
>>anything special I need to do if I want to load this class? It appears it
>
> is
>
>>a classloader issue, but I don't know enough to determine what the problem
>>is. Any help is greatly appreciated!
>>
>>Steve Nakhla
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.362 / Virus Database: 267.12.8/161 - Release Date: 03/11/2005
>
>
>
> ---------------------------------------------------------------------
> 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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.12.8/161 - Release Date: 03/11/2005



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


Re: Load class from different web app

Posted by Tim Funk <fu...@joedog.org>.
Placing classes jdk/jre/lib/ext puts them into the system classloader. This 
opens a whole class of class not found errors and errors related to tomcat 
not reloading classes. (As well as memory leaks due to Classloaders not being 
freed)

-Tim

Michael Forster wrote:

> That is not strictly true, We had an application at work that used JNI and
> was part of a Database access library as well as accessing things like the
> Machines Hostmac address.
> 
> We could not run it from the Tomcat area and had to put it into a jar file
> and put the jar file into the JVM jdk/jre/lib/ext dir and then it worked
> fine as any classes / libraries in that dir are loaded by the JVM meaning
> they are always available - This is also where we put the JDBC driver jar.
> 
> Mike.
> 
> -----Original Message-----
> From: Tim Funk [mailto:funkman@joedog.org]
> Sent: 04 November 2005 11:32
> To: Tomcat Users List
> Subject: Re: Load class from different web app
> 
> 
> You are violating the servlet spec. Do not pass go, do not collect $200.
> 
> Classes for a webapp need to be in WEB-INF/classes and WEB-INF/lib. Tomcat
> does allow for webapps to share classes via the $CATALINA_HOME/shared and
> $CATALINA_HOME/common directories but you'll need to see the classloader
> docs
> on any restrictions.
> 
> -Tim
> 
> Steven Nakhla wrote:
> 
> 
>>I'm writing a web application (a portal app, to be specific) that needs to
>>be able to load a class (using Class.forName(...)) that was deployed in a
>>different web application from the one I am developing. I've deployed the
>>target web app containing the class I want to load, but whenever I call
>>Class.forName(), I get a "java.lang.ClassNotFoundException". Is there
>>anything special I need to do if I want to load this class? It appears it
> 
> is
> 
>>a classloader issue, but I don't know enough to determine what the problem
>>is. Any help is greatly appreciated!
>>
>>Steve Nakhla
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.362 / Virus Database: 267.12.8/161 - Release Date: 03/11/2005
> 
> 
> 
> ---------------------------------------------------------------------
> 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


RE: Load class from different web app

Posted by Michael Forster <mp...@muckworld.com>.
That is not strictly true, We had an application at work that used JNI and
was part of a Database access library as well as accessing things like the
Machines Hostmac address.

We could not run it from the Tomcat area and had to put it into a jar file
and put the jar file into the JVM jdk/jre/lib/ext dir and then it worked
fine as any classes / libraries in that dir are loaded by the JVM meaning
they are always available - This is also where we put the JDBC driver jar.

Mike.

-----Original Message-----
From: Tim Funk [mailto:funkman@joedog.org]
Sent: 04 November 2005 11:32
To: Tomcat Users List
Subject: Re: Load class from different web app


You are violating the servlet spec. Do not pass go, do not collect $200.

Classes for a webapp need to be in WEB-INF/classes and WEB-INF/lib. Tomcat
does allow for webapps to share classes via the $CATALINA_HOME/shared and
$CATALINA_HOME/common directories but you'll need to see the classloader
docs
on any restrictions.

-Tim

Steven Nakhla wrote:

> I'm writing a web application (a portal app, to be specific) that needs to
> be able to load a class (using Class.forName(...)) that was deployed in a
> different web application from the one I am developing. I've deployed the
> target web app containing the class I want to load, but whenever I call
> Class.forName(), I get a "java.lang.ClassNotFoundException". Is there
> anything special I need to do if I want to load this class? It appears it
is
> a classloader issue, but I don't know enough to determine what the problem
> is. Any help is greatly appreciated!
>
> Steve Nakhla
>

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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.12.8/161 - Release Date: 03/11/2005



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


Re: Load class from different web app

Posted by Tim Funk <fu...@joedog.org>.
You are violating the servlet spec. Do not pass go, do not collect $200.

Classes for a webapp need to be in WEB-INF/classes and WEB-INF/lib. Tomcat 
does allow for webapps to share classes via the $CATALINA_HOME/shared and 
$CATALINA_HOME/common directories but you'll need to see the classloader docs 
on any restrictions.

-Tim

Steven Nakhla wrote:

> I'm writing a web application (a portal app, to be specific) that needs to
> be able to load a class (using Class.forName(...)) that was deployed in a
> different web application from the one I am developing. I've deployed the
> target web app containing the class I want to load, but whenever I call
> Class.forName(), I get a "java.lang.ClassNotFoundException". Is there
> anything special I need to do if I want to load this class? It appears it is
> a classloader issue, but I don't know enough to determine what the problem
> is. Any help is greatly appreciated!
> 
> Steve Nakhla
> 

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