Reputation: 11
I want to pass AspectJ load time weaving JVM arguments when starting tomcat server from commandline, something like this:
"%JAVA_HOME%\bin\java"
-ea %_DEBUG%
-Duser.dir="%CATALINA_HOME%\bin"
-DTEST_PLUGINS_HOME=%TEST_HOME%\plugins
-DTEST_HOME="%TEST_HOME%"
-DFrameworksLogFilePath=tomcat\logs\node_jsf.log
-DTEST.useNonPooledUUMAuthenticator
-DTEST_DOMAINS_FILE="%TEST_DOMAINS_FILE%"
-Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%"
-Dcatalina.base="%CATALINA_BASE%"
-Dcatalina.home="%CATALINA_HOME%"
-Djava.io.tmpdir="%CATALINA_TMPDIR%"
-Djava.util.logging.config.file=%CATALINA_HOME%\bin\isplogging.properties
%TEST_JAVA_OPTS%
-classpath "%CLASSPATH%"
-Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader
-Daj.class.path="%TEST_HOME%\testsrc.jar"
-Daj.aspect.path="C:\testAspect.jar;%TEST_HOME%\testsrc.jar"
org.apache.catalina.startup.Bootstrap start
The CLASSPATH
variable points to the aspectjweaver.jar file.
I have added the arguments
Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader
,Daj.class.path=path-to-jar-file-where-the-aspects-should-be-woven
andDaj.aspect.path=path-of-jars-where-aspects-are-present
(the source jar also has some compiled aspect).But, using the above configuration does not work with Tomcat. Do I have to make any other changes related to Tomcat classpath or classloader? If yes, please help.
I tried the same thing without Tomcat and it works fine. Please help me on this. I want to make this work without using Spring.
Upvotes: 1
Views: 1740
Reputation: 334
Well, probably my answer is too late, but I hope it will help others. Some time ago I faced the same problem. Two years were passed, so I use Tomcat 7 and AspectJ 1.8.8 now. So, first of all you don't need to change system class loader. There is java agent feature since Java 5, so AspectJ now uses it for load time weaving. For Tomcat just add this to your %CATALINA_HOME%\setenv.bat:
set JAVA_OPTS=-javaagent:c:\path\to\aspectjweaver.jar
set CLASSPATH=%CLASSPATH%;c:\path\to\your\aspect
Enjoy! :)
Upvotes: 1