You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kalpa Welivitigoda <ca...@gmail.com> on 2016/05/09 10:26:52 UTC

Avoiding some classes being load for webapps

Hi,

I am using tomcat 8.0.28. I am using a custom valve which has a dependency
for slf4j (slf4j jar in in tomcat/lib). I also has a set of webapps which
uses different versions of slf4j (those dependencies are in the WEB-INF/lib
of those webapps). Due to the different versions in tomcat/lib and webapps,
I am getting errors such as NoSuchMethodError.

Is it possible to restrict some classes being loaded for webapps? I am
trying to see whether it is possible to load the slf4j classes required for
the webapps from the slf4j jar in WEB-INF/lib only and not from the jar in
tomcat/lib.

Or is there any other recommended way to address this kind of problems?

Re: Avoiding some classes being load for webapps

Posted by Kalpa Welivitigoda <ca...@gmail.com>.
Hi all,

I dig more into the issue and observed the following and came up with a
solution.

The valve I am using is depending on libthrift and libthrift needs slf4j.
That's the reason to have slf4j in tomcat/lib. The webapp also used slf4j
and it is packed with a higher version of slf4j in WEB-INF/lib of the
webapp. I went through some classloading docs and it seems that the issue
is having two versions (most probably incompatible versions) of slf4j in
the classpath.

The solution or rather the workaround was, I used the maven-shade-plugin
and shaded both slf4j and libthrift jars in tomcat/lib. So now libthrift
looks for something like org.shaded.slf4j.<someclass> which slf4j package
structure has also changed to org.shaded.slf4j. And now the webapp is
deployed and is functioning as expected.



On Mon, May 9, 2016 at 11:09 PM Burghard Britzke <
bubi@charmides.in-berlin.de> wrote:

> Hi Kalpa,
>
> > Am 09.05.2016 um 19:31 schrieb Christopher Schultz <
> chris@christopherschultz.net>:
> >
> > Signierter PGP-Teil
> > Kalpa,
> >
> > On 5/9/16 6:26 AM, Kalpa Welivitigoda wrote:
> > > Hi,
> > >
> > > I am using tomcat 8.0.28. I am using a custom valve which has a
> > > dependency for slf4j (slf4j jar in in tomcat/lib). I also has a set
> > > of webapps which uses different versions of slf4j (those
> > > dependencies are in the WEB-INF/lib of those webapps). Due to the
> > > different versions in tomcat/lib and webapps, I am getting errors
> > > such as NoSuchMethodError.
> > >
> > > Is it possible to restrict some classes being loaded for webapps? I
> > > am trying to see whether it is possible to load the slf4j classes
> > > required for the webapps from the slf4j jar in WEB-INF/lib only and
> > > not from the jar in tomcat/lib.
> > >
> > > Or is there any other recommended way to address this kind of
> > > problems?
> >
> > Ideally, there should be no problem, here: the web application should
> > be using its own classes from WEB-INF/lib and Tomcat should be using
> > its own separate classes for its internal operations (including
> > running Valves).
> >
> > Do you have a stack trace of the NSME? I wonder if there's a place in
> > Tomcat where the context ClassLoader isn't being correctly-set.
> >
> > -chris
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
> Did you install slf4j.jar in $java_home/lib/ext folder? those libraries
> are in the class path before all other user libraries. you are able to
> determine from where will/has been is loaded.
>
>
> --
Best Regards,
Kalpa Welivitigoda
http://about.me/callkalpa

Re: Avoiding some classes being load for webapps

Posted by Burghard Britzke <bu...@charmides.in-berlin.de>.
Hi Kalpa,

> Am 09.05.2016 um 19:31 schrieb Christopher Schultz <ch...@christopherschultz.net>:
> 
> Signierter PGP-Teil
> Kalpa,
> 
> On 5/9/16 6:26 AM, Kalpa Welivitigoda wrote:
> > Hi,
> >
> > I am using tomcat 8.0.28. I am using a custom valve which has a
> > dependency for slf4j (slf4j jar in in tomcat/lib). I also has a set
> > of webapps which uses different versions of slf4j (those
> > dependencies are in the WEB-INF/lib of those webapps). Due to the
> > different versions in tomcat/lib and webapps, I am getting errors
> > such as NoSuchMethodError.
> >
> > Is it possible to restrict some classes being loaded for webapps? I
> > am trying to see whether it is possible to load the slf4j classes
> > required for the webapps from the slf4j jar in WEB-INF/lib only and
> > not from the jar in tomcat/lib.
> >
> > Or is there any other recommended way to address this kind of
> > problems?
> 
> Ideally, there should be no problem, here: the web application should
> be using its own classes from WEB-INF/lib and Tomcat should be using
> its own separate classes for its internal operations (including
> running Valves).
> 
> Do you have a stack trace of the NSME? I wonder if there's a place in
> Tomcat where the context ClassLoader isn't being correctly-set.
> 
> -chris
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

Did you install slf4j.jar in $java_home/lib/ext folder? those libraries are in the class path before all other user libraries. you are able to determine from where will/has been is loaded.



Re: Avoiding some classes being load for webapps

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kalpa,

On 5/9/16 6:26 AM, Kalpa Welivitigoda wrote:
> Hi,
> 
> I am using tomcat 8.0.28. I am using a custom valve which has a
> dependency for slf4j (slf4j jar in in tomcat/lib). I also has a set
> of webapps which uses different versions of slf4j (those
> dependencies are in the WEB-INF/lib of those webapps). Due to the
> different versions in tomcat/lib and webapps, I am getting errors
> such as NoSuchMethodError.
> 
> Is it possible to restrict some classes being loaded for webapps? I
> am trying to see whether it is possible to load the slf4j classes
> required for the webapps from the slf4j jar in WEB-INF/lib only and
> not from the jar in tomcat/lib.
> 
> Or is there any other recommended way to address this kind of
> problems?

Ideally, there should be no problem, here: the web application should
be using its own classes from WEB-INF/lib and Tomcat should be using
its own separate classes for its internal operations (including
running Valves).

Do you have a stack trace of the NSME? I wonder if there's a place in
Tomcat where the context ClassLoader isn't being correctly-set.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlcwyV8ACgkQ9CaO5/Lv0PCVOgCgtxVoQpFhNSb+vu9BOhVqHe6X
rhcAoL62A04gbCWACnYGYxq8OzGnrHOB
=LkIC
-----END PGP SIGNATURE-----

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