Is it possible to add the aspectj load-time agent when start a program with -jar ?
With Jetty, if I start
java -javaagent:aspectjweaver-1.8.0.jar -c
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
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.