I'm having a problem trying to make eclipse and aspectj work for Dynamic Web Projects. I'm looking for compile time weaving so I can use the Eclipse Visualisation features.
I've followed the steps given here:
https://forums.oracle.com/forums/thread.jspa?messageID=8591748
using Eclipse Indigo (3.7) with the latest Aspectj eclipse plugin (2.1.3).
The steps were as follows:
[1] Create basic servlet
//imports omitted
public class MyServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response){
PrintWriter out= null;
try {
out = response.getWriter();
out.write("hello from MyServlet");
} catch (IOException e) {
e.printStackTrace();
} finally {
if(out!=null)
out.close();
}
}
}
[2] Add servlet to deployment discriptor (web.xml)
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.myCompany.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet/*</url-pattern>
</servlet-mapping>
</web-app>
[3] Create aspect
package com.myCompany;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public aspect MyServletAspect {
pointcut doGet() :
execution(public void MyServlet.doGet(HttpServletRequest,HttpServletResponse));
after() returning : doGet() {
System.out.println("Hello from doGet (via aspectj)");
}
}
However when I run this no dice - the aspect just doesn't run (servlet writes to response, aspect to console). I did something similar for a regular java project and that works fine.
I note there are guidelines for adding aop.xml into the web app's META-INF directory, however this didn't work for me.
Our goal is to run aspectj non-invasively in development via eclipse for a non-Spring framework (or Maven) project - this should be easy.. but I haven't been able to make it work.
Any suggestions / reference to tutorial for compile-time weaving for web apps in eclipse would be useful. The app server is embedded Tomcat 6 (but can be upgraded to tomcat 7 if required).
The ability to tweak the development environment at runtime without impacting the production code would be great - if it can be made to work. Responses much appreciated.