如何使用AspectJ和Tomcat配置加载时编织? [英] How to configure load-time weaving with AspectJ and Tomcat?

查看:439
本文介绍了如何使用AspectJ和Tomcat配置加载时编织?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以下一种方式配置加载时编织(用于使用Perf4J进行分析):

I tried to configure load-time weaving (for doing profiling with Perf4J) in the next way:

1)我添加了 aop。 xml META-INF 文件夹。部署时,META-INF放置在工件根目录中(即 MyAppDeployed / META-INF )。

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

2)我把 aspectjrt-1.6.1.jar aspectjweaver-1.6.1.jar commons-jexl-1.1.jar commons-logging.jar Tomcat / lib 文件夹(起初我试过 MyAppDeployed / WEB-INF / libs 但它也没有用。)

2) I put aspectjrt-1.6.1.jar, aspectjweaver-1.6.1.jar, commons-jexl-1.1.jar, commons-logging.jar to the Tomcat/lib folder (at first I tried MyAppDeployed/WEB-INF/libs but it also didn't work).

3)我在VM选项中添加了 -javaagent:C:\ apache-tomcat-6.0.33 \lib \ aspectjweaver-1.6.1.jar 启动Tomcat。

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

4)我的 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 don't see any signs that load-time weaving happens. Neither error-reports nor necessary 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

在我指定javaagent参数时在 aspectjweaver-1.6.1.jar 名称中出错时的情况。如果写得正确 - 不会打印错误信息。

in a case when I do a mistake in a aspectjweaver-1.6.1.jar name when specify a javaagent parameter. If it's written correctly - no error messages are printed.

任何想法,我做错了什么?

Any ideas, what am I doing wrong?

P.S。我使用Java 5,我尝试使用 1.5.4 版本的aspectj完全相同的结果。

P.S. I use Java 5, and I tried the same things with 1.5.4 version of the aspectj with exactly the same results.

推荐答案

我试图在Tomcat中解决同样的问题。除了-javaagent选项之外,还需要确保aop.xml必须位于WEB-INF / classes / META-INF目录下。这对我来说有所不同。

I was trying to solve the same issue in Tomcat. In addition to -javaagent option, you need to make sure the aop.xml must be under the WEB-INF/classes/META-INF dir. This made the difference for me.

这篇关于如何使用AspectJ和Tomcat配置加载时编织?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆