You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Thorsten Schöning <ts...@am-soft.de> on 2023/04/16 11:36:29 UTC

How to have a custom classloader outside Tomcat's own lib-dir?

Hi everyone,

I have some app consisting of a directory layout with some bundled
Tomcat, containing at least one exploded webapp. For various reasons,
that webbapp needs its own classloader, which is currently configured
in context.xml of Tomcat and stored in its own lib-dir. I don't like
putting custom JARs into the default deployment of Tomcat too much.

> <!-- use own classloader, reading classpath file -->
> <Loader loaderClass="[...]" delegate="true"/>

So, is there some way to put the JAR elsewhere?

Whatever I tested didn't work, e.g. adding the JAR to "common.loader".
But I must admit that I didn't fully understand if common.loader is
used to load the custom loader at all or only afterwards and stuff.

Or is there some way to not use Tomcat's "Loader" above and only
maintain a custom, webapp-specific classloader in the one webapp
needing it?

I've searched for somethign like "setClassLoader" and found it for
some servlet containers, but it doesn't seem to be standard and
supported by Tomcat.

Thanks for your input!

Mit freundlichen Grüßen

Thorsten Schöning

-- 
AM-SoFT IT-Service - Bitstore Hameln GmbH
Mitglied der Bitstore Gruppe - Ihr Full-Service-Dienstleister für IT und TK

E-Mail: Thorsten.Schoening@AM-SoFT.de
Web:    http://www.AM-SoFT.de/

Tel:   +49 5151-  9468- 0
Tel:   +49 5151-  9468-55
Mobil: +49  178-8 9468-04

AM-SoFT IT-Service - Bitstore Hameln GmbH, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 221853 - Geschäftsführer: Janine Galonska


Für Rückfragen stehe ich Ihnen jederzeit zur Verfügung. 

Mit freundlichen Grüßen, 

Thorsten Schöning


Telefon: +49 5151 9468-55
Fax: 
E-Mail: TSchoening@am-soft.de

AM-Soft IT-Service - Bitstore Hameln GmbH
Brandenburger Straße 7c
31789 Hameln

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen und ist ausschliesslich für den Adressaten bestimmt. Jeglicher Zugriff auf diese E-Mail durch andere Personen als den Adressaten ist untersagt. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Sollten Sie nicht der für diese E-Mail bestimmte Adressat sein, ist Ihnen jede Veröffentlichung, Vervielfältigung oder Weitergabe wie auch das Ergreifen oder Unterlassen von Massnahmen im Vertrauen auf erlangte Information untersagt. 

This e-mail may contain confidential and/or privileged information and is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. 

Hinweise zum Datenschutz: bitstore.group/datenschutz




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


Re: How to have a custom classloader outside Tomcat's own lib-dir?

Posted by BRUNO MELLONI <Br...@chickasaw.net>.
Perhaps this info will help:

- Custom class loaders are supposed to be possible but very poorly documented.  I was never able to make them work properly.   You might have some luck if you study the source code of Tomcat itself, as it does implement them.

- Webapps really expect all custom library jars to be loaded from web-inf/lib.

- up to Java 8 you could write code to dynamically add to the class path.  I used to use that ability extensively, even though I was not really using a custom classloader.   Starting in Java 9 they broke that capability.

- In tomcat/conf/catalina.prooerties you can add jars and folders to the common class path.  It is discouraged but it might get you out of trouble in a pinch.

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: Mark Thomas <ma...@apache.org>
Sent: Monday, April 17, 2023 5:13:44 AM
To: users@tomcat.apache.org <us...@tomcat.apache.org>
Subject: Re: How to have a custom classloader outside Tomcat's own lib-dir?

On 16/04/2023 12: 36, Thorsten Schöning wrote: > Hi everyone, > > I have some app consisting of a directory layout with some bundled > Tomcat, containing at least one exploded webapp. For various reasons, What are those reasons?
ZjQcmQRYFpfptBannerStart
CAUTION: This Message Is From an External Source
This message originated outside the Chickasaw Nation. Do not click links or open attachments unless you recognize the sender and know the content is safe!
<https://us-phishalarm-ewt.proofpoint.com/EWT/v1/IMeFMrRG1GeY!JdtefBv6lkGaCCOnym3mtjzgmrjMjSYDB5WKcB11z7TBBrnWuL4Jtfa62KewlWqxRNdE_fW-DtvIVBInDg5L3XkWe9I8yWgbNjAAnqx-$>
Report Suspicious

ZjQcmQRYFpfptBannerEnd

On 16/04/2023 12:36, Thorsten Schöning wrote:
> Hi everyone,
>
> I have some app consisting of a directory layout with some bundled
> Tomcat, containing at least one exploded webapp. For various reasons,

What are those reasons? I'm wondering if the reasons have any impact on
the answer.

> that webbapp needs its own classloader, which is currently configured
> in context.xml of Tomcat and stored in its own lib-dir. I don't like
> putting custom JARs into the default deployment of Tomcat too much.
>
>> <!-- use own classloader, reading classpath file -->
>> <Loader loaderClass="[...]" delegate="true"/>
>
> So, is there some way to put the JAR elsewhere?

Yes, as long as you tell Tomcat where to find it.

> Whatever I tested didn't work, e.g. adding the JAR to "common.loader".

That should have worked and is the approach I'd recommend. Exactly what
did you change when you tried this?

> But I must admit that I didn't fully understand if common.loader is
> used to load the custom loader at all or only afterwards and stuff.
>
> Or is there some way to not use Tomcat's "Loader" above and only
> maintain a custom, webapp-specific classloader in the one webapp
> needing it?

No. Tomcat needs to be able to load the custom class loader in order to
configure it.

Mark


>
> I've searched for somethign like "setClassLoader" and found it for
> some servlet containers, but it doesn't seem to be standard and
> supported by Tomcat.
>
> Thanks for your input!
>
> Mit freundlichen Grüßen
>
> Thorsten Schöning
>

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



Re: How to have a custom classloader outside Tomcat's own lib-dir?

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Thorsten Schöning,
am Montag, 17. April 2023 um 13:16 schrieben Sie:

>> common.loader=[...],"${catalina.base}/lib_custom/*.jar"
>> common.loader=[...],"${catalina.home}/lib_custom/*.jar"
>> common.loader=[...],"${catalina.base}/lib_custom/custom.jar"
>> common.loader=[...],"${catalina.home}/lib_custom/custom.jar"

No idea what I did wrong before, but this works now as long as I have
the correct path to the JAR.

> common.loader="[...],"${catalina.base}/Tomcat_ClassLoader.jar"
> common.loader="[...],"${catalina.base}/webapps/RIFF/WEB-INF/lib/Tomcat_ClassLoader.jar"

Mit freundlichen Grüßen

Thorsten Schöning

-- 
AM-SoFT IT-Service - Bitstore Hameln GmbH
Mitglied der Bitstore Gruppe - Ihr Full-Service-Dienstleister für IT und TK

E-Mail: Thorsten.Schoening@AM-SoFT.de
Web:    http://www.AM-SoFT.de/

Tel:   +49 5151-  9468- 0
Tel:   +49 5151-  9468-55
Mobil: +49  178-8 9468-04

AM-SoFT IT-Service - Bitstore Hameln GmbH, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 221853 - Geschäftsführer: Janine Galonska


Für Rückfragen stehe ich Ihnen jederzeit zur Verfügung. 

Mit freundlichen Grüßen, 

Thorsten Schöning


Telefon: +49 5151 9468-55
Fax: 
E-Mail: TSchoening@am-soft.de

AM-Soft IT-Service - Bitstore Hameln GmbH
Brandenburger Straße 7c
31789 Hameln

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen und ist ausschliesslich für den Adressaten bestimmt. Jeglicher Zugriff auf diese E-Mail durch andere Personen als den Adressaten ist untersagt. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Sollten Sie nicht der für diese E-Mail bestimmte Adressat sein, ist Ihnen jede Veröffentlichung, Vervielfältigung oder Weitergabe wie auch das Ergreifen oder Unterlassen von Massnahmen im Vertrauen auf erlangte Information untersagt. 

This e-mail may contain confidential and/or privileged information and is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. 

Hinweise zum Datenschutz: bitstore.group/datenschutz




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


Re: How to have a custom classloader outside Tomcat's own lib-dir?

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Mark Thomas,
am Montag, 17. April 2023 um 12:13 schrieben Sie:

> What are those reasons? I'm wondering if the reasons have any impact on the answer.

Unlikely, it's about business logic. The custom classloader uses some
custom config file to maintain additional JARs for the classloader
based on a custom feature system enabling/disabling things.

For the time being that classloader is needed, but the interesting
question is where the JAR file is stored and where the classloader is
actually enabled/used. If it really needs to be in some Tomcat server
side config or can be placed into a webapp.

> That should have worked and is the approach I'd recommend. Exactly
> what did you change when you tried this?

Something along the following, don't have the exact lines anymore.
Need to try again at some later time not that I know it's the correct
approach at all in theory.

> common.loader=[...],"${catalina.base}/lib_custom/*.jar"
> common.loader=[...],"${catalina.home}/lib_custom/*.jar"
> common.loader=[...],"${catalina.base}/lib_custom/custom.jar"
> common.loader=[...],"${catalina.home}/lib_custom/custom.jar"

> No. Tomcat needs to be able to load the custom class loader in order to configure it.

Just to be sure: I don't necessarily need Tomcat-level classloader,
but webapp-specific might be sufficient. But on that level there's no
way to use a custom classloader or is there?

I'm e.g. using Axis2 as a webapp in Tomcat and that does support a
custom classloader. But that is simply because it does so on its own,
have nothign to do with Servlet standards?

Mit freundlichen Grüßen

Thorsten Schöning

-- 
AM-SoFT IT-Service - Bitstore Hameln GmbH
Mitglied der Bitstore Gruppe - Ihr Full-Service-Dienstleister für IT und TK

E-Mail: Thorsten.Schoening@AM-SoFT.de
Web:    http://www.AM-SoFT.de/

Tel:   +49 5151-  9468- 0
Tel:   +49 5151-  9468-55
Mobil: +49  178-8 9468-04

AM-SoFT IT-Service - Bitstore Hameln GmbH, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 221853 - Geschäftsführer: Janine Galonska


Für Rückfragen stehe ich Ihnen jederzeit zur Verfügung. 

Mit freundlichen Grüßen, 

Thorsten Schöning


Telefon: +49 5151 9468-55
Fax: 
E-Mail: TSchoening@am-soft.de

AM-Soft IT-Service - Bitstore Hameln GmbH
Brandenburger Straße 7c
31789 Hameln

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen und ist ausschliesslich für den Adressaten bestimmt. Jeglicher Zugriff auf diese E-Mail durch andere Personen als den Adressaten ist untersagt. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Sollten Sie nicht der für diese E-Mail bestimmte Adressat sein, ist Ihnen jede Veröffentlichung, Vervielfältigung oder Weitergabe wie auch das Ergreifen oder Unterlassen von Massnahmen im Vertrauen auf erlangte Information untersagt. 

This e-mail may contain confidential and/or privileged information and is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. 

Hinweise zum Datenschutz: bitstore.group/datenschutz




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


Re: How to have a custom classloader outside Tomcat's own lib-dir?

Posted by Mark Thomas <ma...@apache.org>.
On 16/04/2023 12:36, Thorsten Schöning wrote:
> Hi everyone,
> 
> I have some app consisting of a directory layout with some bundled
> Tomcat, containing at least one exploded webapp. For various reasons,

What are those reasons? I'm wondering if the reasons have any impact on 
the answer.

> that webbapp needs its own classloader, which is currently configured
> in context.xml of Tomcat and stored in its own lib-dir. I don't like
> putting custom JARs into the default deployment of Tomcat too much.
> 
>> <!-- use own classloader, reading classpath file -->
>> <Loader loaderClass="[...]" delegate="true"/>
> 
> So, is there some way to put the JAR elsewhere?

Yes, as long as you tell Tomcat where to find it.

> Whatever I tested didn't work, e.g. adding the JAR to "common.loader".

That should have worked and is the approach I'd recommend. Exactly what 
did you change when you tried this?

> But I must admit that I didn't fully understand if common.loader is
> used to load the custom loader at all or only afterwards and stuff.
> 
> Or is there some way to not use Tomcat's "Loader" above and only
> maintain a custom, webapp-specific classloader in the one webapp
> needing it?

No. Tomcat needs to be able to load the custom class loader in order to 
configure it.

Mark


> 
> I've searched for somethign like "setClassLoader" and found it for
> some servlet containers, but it doesn't seem to be standard and
> supported by Tomcat.
> 
> Thanks for your input!
> 
> Mit freundlichen Grüßen
> 
> Thorsten Schöning
> 

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