Kanan Totawar
Kanan Totawar

Reputation: 11

How to use AspectJ load time weaving with Tomcat? (without Spring)

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

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

Answers (1)

Andrew
Andrew

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

Related Questions