You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Arshan Dabirsiaghi <ar...@aspectsecurity.com> on 2010/04/06 06:04:23 UTC
Major Tomcat classloading issues with javaagent command line switch
Hi,
Has anybody had any success the "javaagent:" switch with Tomcat on the
command line? I've tested using Tomcat 5.5.28 and Tomcat 6.0, with both
JDK 1.5 and 1.6 through the Eclipse WTP plugin, and I always run into a
very peculiar problem. When using an agent, no servlets defined in the
web.xml work, even with an agent that does literally nothing due to a
NoClassDefFoundError. I've included a zipped-up Eclipse WTP project that
reproduces the issue.
Try running the project [1] on your own system with a javaagent switch
to an agent that does nothing (like /build/classes/aspect.jar in my
zip). Every time a servlet is visited, the following exception is
encountered:
javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
93)
...
root cause:
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
java.lang.ClassLoader.findBootstrapClass(Native Method)
java.lang.ClassLoader.findBootstrapClass0(ClassLoader.java:892)
java.lang.ClassLoader.loadClass(ClassLoader.java:302)
java.lang.ClassLoader.loadClass(ClassLoader.java:300)
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
java.lang.ClassLoader.loadClass(ClassLoader.java:252)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader
.java:1302)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader
.java:1233)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
93)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:84
9)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Thread.java:619)
The bottom line appears to be this: across Tomcat and JDK versions, you
can't use the javaagent switch and have a working web app.
Steps to reproduce (for Tomcat 6, you might have to fiddle with the
project facet configs for Tomcat 5.5):
1. Download zip from http://i8jesus.com/stuff/JeffAgent.zip
2. Extract zip to <wherever>
3. In Eclipse (w/ WTP), import an existing project into your workspsace,
sourced at <wherever>
4. Go to Run Configurations
5. Select your Apache Tomcat 6 run configuration
6. Add -javaagent:<wherever>/build/classes/aspect.jar to the VM
arguments (and apply/save)
7. Add the JeffAgent project added in step #3 to the Tomcat server
8. Start the Apache server (through WTP)
9. Try visiting the servlet at http://localhost:8080/JeffAgent/Jeff
10. See the exception shown above
Now, to see why I'm really confused, take out the "javaagent" switch
added in step #6, restart the server, and see that the servlet operates
normally.
Does anyone have any experiences to share using javaagent (or
instrumentation, period) on the big application servers? Although the
message indicates it's a simple classloading issue, debugging has proved
quite difficult. This is not the case of a misplaced servlet-api.jar, or
something to that effect. The mere presence of an agent makes the
servlet container incapable of finding many classes it would otherwise
be able to find.
Please help!
Thanks,
Arshan
Re: Major Tomcat classloading issues with javaagent command line
switch
Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/4/7 Arshan Dabirsiaghi <ar...@aspectsecurity.com>:
> Just to close the loop here, the problem was that the class was being loaded twice - once from inside the *agent* jar, and another duplicate later from WEB-INF/classes. I guess Tomcat or Java was confused as to which version they wanted to use. Not 100% sure what happened, but removing it from the agent jar fixed the problem.
The servlet spec requires that the webapp classes and libraries were
preferred over the ones provided by Tomcat. More details in [1] At
the same time, web applications are short-lived and can be stopped /
undeployed at any time, at which point their classloader and their
classes become unavailable. Using those for something that is
JVM-wide may lead to leaked memory at best, or do not work at all.
[1] http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Major Tomcat classloading issues with javaagent command line switch
Posted by Arshan Dabirsiaghi <ar...@aspectsecurity.com>.
Just to close the loop here, the problem was that the class was being loaded twice - once from inside the *agent* jar, and another duplicate later from WEB-INF/classes. I guess Tomcat or Java was confused as to which version they wanted to use. Not 100% sure what happened, but removing it from the agent jar fixed the problem.
Thanks!
Arshan
-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net]
Sent: Tuesday, April 06, 2010 11:50 AM
To: Tomcat Users List
Subject: Re: Major Tomcat classloading issues with javaagent command line switch
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Arshan,
On 4/6/2010 11:18 AM, Christopher Schultz wrote:
> The command line for my running JVM looks like this:
>
> /usr/bin/java -Dnop -Xmx64M
> -agentpath:/home/cschultz/yjp-8.0.6/bin/linux-x86-32/libyjpagent.so=
Sorry, I didn't see that you were using a Java-language agent. I haven't
tried this.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAku7WDUACgkQ9CaO5/Lv0PBGTACdG2gUuUsT55SlfDKKOGgagp27
qG4An2LtLnwavrnj79jPJ6oUwQZowhhW
=Mx79
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Major Tomcat classloading issues with javaagent command line
switch
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Arshan,
On 4/6/2010 11:18 AM, Christopher Schultz wrote:
> The command line for my running JVM looks like this:
>
> /usr/bin/java -Dnop -Xmx64M
> -agentpath:/home/cschultz/yjp-8.0.6/bin/linux-x86-32/libyjpagent.so=
Sorry, I didn't see that you were using a Java-language agent. I haven't
tried this.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAku7WDUACgkQ9CaO5/Lv0PBGTACdG2gUuUsT55SlfDKKOGgagp27
qG4An2LtLnwavrnj79jPJ6oUwQZowhhW
=Mx79
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Major Tomcat classloading issues with javaagent command line
switch
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Arshan,
On 4/6/2010 12:04 AM, Arshan Dabirsiaghi wrote:
> The bottom line appears to be this: across Tomcat and JDK versions, you
> can't use the javaagent switch and have a working web app.
This works for me under the following environment:
$ bin/catalina.sh version
Using CATALINA_BASE: /usr/local/apache-tomcat-6.0.26
Using CATALINA_HOME: /usr/local/apache-tomcat-6.0.26
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.26/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-6.0.26/bin/bootstrap.jar
Server version: Apache Tomcat/6.0.26
Server built: March 9 2010 1805
Server number: 6.0.26.0
OS Name: Linux
OS Version: 2.6.18-14-fza-686-bigmem
Architecture: i386
JVM Version: 1.6.0_12-b04
JVM Vendor: Sun Microsystems Inc.
The command line for my running JVM looks like this:
/usr/bin/java -Dnop -Xmx64M
- -agentpath:/home/cschultz/yjp-8.0.6/bin/linux-x86-32/libyjpagent.so=
- -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
- -Djava.endorsed.dirs=/usr/local/apache-tomcat-6.0.26/endorsed -classpath
/usr/local/apache-tomcat-6.0.26/bin/bootstrap.jar
- -Dcatalina.base=/home/cschultz/.webapps/xxx
- -Dcatalina.home=/usr/local/apache-tomcat-6.0.26
- -Djava.io.tmpdir=/home/cschultz/.webapps/xxx/temp
org.apache.catalina.startup.Bootstrap start
What does yours look like?
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAku7UNUACgkQ9CaO5/Lv0PCxFwCfa5/zxoTvyYF5x9/sNy2STxGY
Pb8AoIMd66jZvvTqqmu1yTZzg2/+U0Np
=8BCW
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Major Tomcat classloading issues with javaagent command line switch
Posted by Arshan Dabirsiaghi <ar...@aspectsecurity.com>.
I've tried this outside Eclipse with Tomcat 6.0.26 on both Java 1.5.0_22
and Java 1.6.0_18:
SET JAVA_OPTS=-javaagent:C:\path-to-agent.jar
JSP's seem to work fine, but anytime you try to access a Servlet you get
the same thing:
javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
98)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.j
ava:859)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.proce
ss(Http11AprProtocol.java:579)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
java.lang.Thread.run(Thread.java:619)
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
java.lang.ClassLoader.findBootstrapClass(Native Method)
java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:927)
java.lang.ClassLoader.loadClass(ClassLoader.java:298)
java.lang.ClassLoader.loadClass(ClassLoader.java:296)
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
java.lang.ClassLoader.loadClass(ClassLoader.java:248)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader
.java:1431)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader
.java:1361)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
98)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.j
ava:859)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.proce
ss(Http11AprProtocol.java:579)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
java.lang.Thread.run(Thread.java:619)
Can anyone else confirm?
Arshan
-----Original Message-----
From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
Sent: Tuesday, April 06, 2010 12:34 AM
To: Tomcat Users List
Subject: RE: Major Tomcat classloading issues with javaagent command
line switch
> From: Arshan Dabirsiaghi
[mailto:arshan.dabirsiaghi@aspectsecurity.com]
> Subject: Major Tomcat classloading issues with javaagent command line
> switch
>
> The bottom line appears to be this: across Tomcat and JDK versions,
you
> can't use the javaagent switch and have a working web app.
Wrong conclusion. Try running Tomcat directly, not under Eclipse; the
problem you're having is most likely due to Eclipse insisting on doing
things its own way, ignoring configuration that you have set up. Deploy
your war to a stand-alone Tomcat and try it again.
- 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.
---------------------------------------------------------------------
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: Major Tomcat classloading issues with javaagent command line
switch
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Arshan Dabirsiaghi [mailto:arshan.dabirsiaghi@aspectsecurity.com]
> Subject: Major Tomcat classloading issues with javaagent command line
> switch
>
> The bottom line appears to be this: across Tomcat and JDK versions, you
> can't use the javaagent switch and have a working web app.
Wrong conclusion. Try running Tomcat directly, not under Eclipse; the problem you're having is most likely due to Eclipse insisting on doing things its own way, ignoring configuration that you have set up. Deploy your war to a stand-alone Tomcat and try it again.
- 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.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org