加载时编织和java -jar [英] Load-time weaving and java -jar

查看:100
本文介绍了加载时编织和java -jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用-jar启动程序时是否可以添加Aspectj加载时间代理?

Is it possible to add the aspectj load-time agent when start a program with -jar ?

有了Jetty,如果我开始

With Jetty, if I start

java -javaagent:aspectjweaver-1.8.0.jar -classpath toto.jar -jar start.jar

aspectj不适用.但是如果我打电话给我

The aspectj is not apply. But I if call

java -javaagent:aspectjweaver-1.8.0.jar -classpath toto.jar;start.jar org.eclipse.jetty.start.Main

一切都很好.

推荐答案

-cp (...) my.MainClass方法相比,-jar和LTW的问题似乎是类加载顺序有所不同.可能是在用-jar指定的JAR加载之前,编织人员才能在类路径上的方面JAR中看到方面和META-INF/aop-ajc.xml.我找到了一种解决方法,但这不是很好:您可以将方面JAR放在JVM的启动类路径中,但是在这种情况下,即使在编织代理程序之前也要加载方面.因此,您还必须在启动类路径中添加aspectjrt.jar:

The problem with -jar and LTW seems to be that there is something different with the classloading order compared to the -cp (...) my.MainClass approach. Probably the JAR specified with -jar is loaded before the weaver can see the aspects and META-INF/aop-ajc.xml in the aspect JAR on the classpath. I found a workaround, but it is not nice: You can put the aspect JAR on the JVM's boot classpath, but in this case the aspects are loaded even before the weaving agent. Thus you also have to add aspectjrt.jar to the boot classpath:

java -Xbootclasspath/a:aspect.jar;lib\aspectjrt.jar -javaagent:lib\aspectjweaver.jar -jar application.jar

考虑到这种情况,我认为最好将应用程序JAR添加到普通的类路径并手动指定主类.但这是一个品味问题,以及在启动应用程序时是否知道主类名称.

Considering this circumstance, I guess it is preferable to add the application JAR to the normal classpath and specify the main class manually. But it is a matter of taste and whether you know the main class name when starting your application.

这篇关于加载时编织和java -jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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