How to configure time loading using AspectJ and Tomcat?

I tried setting up temporary weaving (to perform profiling using Perf4J) as follows:

1) I added the aop.xml folder to META-INF . When deployed, META-INF is placed in the root directory of the artifact (i.e. MyAppDeployed/META-INF ).

2) I put aspectjrt-1.6.1.jar , aspectjweaver-1.6.1.jar , commons-jexl-1.1.jar , commons-logging.jar in the Tomcat/lib folder (I tried MyAppDeployed/WEB-INF/libs , but it also did not work).

3) I added the options -javaagent:C:\apache-tomcat-6.0.33\lib\aspectjweaver-1.6.1.jar to the VM when starting Tomcat.

4) My aop.xml :

 <!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> <aspectj> <aspects> <aspect name="org.perf4j.log4j.aop.TimingAspect"/> </aspects> <weaver options="-verbose -showWeaveInfo"> <include within="com.mypackages.MyClass"/> </weaver> </aspectj> 

I see no signs that interweaving in time is occurring. No error reports, no required results. The only error message I have is:

 Error occurred during initialization of VM agent library failed to init: instrument Error opening zip file: C:\apache-tomcat-6.0.33\lib\wrong-jar.jar 

in case of an error in the name aspectjweaver-1.6.1.jar when specifying the javaagent parameter. If it is correctly written, error messages are not printed.

Any ideas what I'm doing wrong?

PS I use Java 5 and I tried the same things with 1.5.4 aspectj version with exactly the same results.

+8
java tomcat aspectj load-time-weaving perf4j
source share
2 answers

If you want to use load time weaving, you can first compile your classes with javac, as usual, then compile your aspect with (i) ajc. You can do this with the ant task as shown below

 <target name="compile-aspect"> <iajc source="1.6" target="1.6" showweaveinfo="true" verbose="true" outxml="true" debug="true" outjar="${dist.dir}/myaspect.jar"> <argfiles> <pathelement location="${src.dir}/sources.lst"/> </argfiles> <classpath> <path refid="master-classpath" /> </classpath> </iajc> </target> 

It is enough to have aspectjrt.jar in the classpath ("master-class path") at compile time.

Since all of my Java classes are in $ {src.dir}, I provide the original iajc list. There is only one line in the list of sources.

sources.lst

 com/xx/yy/zz/LoggingAspect.java 

I set some iajc task attributes as follows

 outxml="true" outjar="jar_file_name" 

When I run the compilation task, I have a jar file jar_file_name.jar containing

 META-INF/MANIFEST.MF com/xx/yy/zz/LoggingAspect.class META-INF/aop-ajc.xml 

Finally, add * jar_file_name.jar * to your WEB-INF / lib folder in your web application.

Then run Tomcat with -javaagents: /path_to_aspectjweaver.jar , as you did before.

When I put aop.xml (or aop-ajc.xml) in META-INF under the war file directly, it does not work. This way (I mean class separation aspect in jar) just works fine for me.

Hope this helps.

+4
source share

I tried to solve the same problem in Tomcat. In addition to the -javaagent option, you must ensure that aop.xml must be in the WEB-INF / classes / META-INF directory. It mattered to me.

+4
source share

All Articles