Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Configuring Tomcat for AspectJ

807580Aug 7 2009 — edited Aug 24 2010
I created an aspect/tomcat project using the aspectj Eclipse plugin for Eclipse. I ran the code stand-alone and it prints a message to the console which verifies it works. Next, I ran a servlet in Tomcat5.5.27 (with jdk1.6.0_10) that the aspect should interact with. I see no output in the console from the aspect (however, a lone System.out.println() works which shows me the output is not directed to the log file). Does anyone know of a web site that has step by step instructions on exactly how to set up aspectJ for Tomcat? I've been to a lot of web sites where the instructions are incomplete such as:
http://static.springsource.org/spring/docs/2.5.x/reference/orm.html#orm-jpa-setup-lcemfb-tomcat


Here is what I have so far
(it doesnt work, says "java.lang.NoClassDefFoundError: org/apache/catalina/loader/WebappClassLoader").
It uses Spring's jar files:


Deployment on Tomcat:

* Add this to c:/Program Files/Tomcat/Tomcat5.5.27/conf/Catalina/localhost/MyProject.xml (just below the opening <Context> tag):

<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
<context:load-time-weaver />


* Add these to c:\Program Files\Tomcat\Tomcat5.5.27\common\lib:

aspectjrt.jar
aspectjtools.jar
aspectjweaver.jar
org.aspectj.matcher
spring-tomcat-weaver.jar
spring-agent.jar

* Add this to catalina.bat, (added at a specific location in the file):
set JAVA_OPTS=%JAVA_OPTS% -javaagent:C:\Program Files\Tomcat\Tomcat5.5.27\common\lib\spring-agent.jar -Xms64m -Xmx200m


* Add a new file called aop-ajc.xml to the project's WEB-INF/lib folder with this content:

<!DOCTYPE aspectj PUBLIC
        "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">

<aspectj>
    <weaver>
       <include within="com.*"/>
    </weaver>
	<aspects>
		<aspect name="com.myCompany.myProject.aj.PreparedStatementAspect"/>
	</aspects>
</aspectj>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2010
Added on Aug 7 2009
8 comments
4,540 views