You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

j2ee.adoc 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. = Using AspectJ in servlets
  2. _Last updated: 2003-09-27 by wisberg_
  3. This contains short notes on using AspectJ with various J2EE servers and
  4. deployment tools.
  5. == Generally
  6. AspectJ programs work if run in the same namespace and with
  7. aspectjrt.jar. Servlet runners and J2EE web containers should run
  8. AspectJ programs fine if the classes and required libraries are deployed
  9. as usual. As with any shared library, if more than one application is
  10. using AspectJ, then the aspectjrt.jar should be deployed where it will
  11. be loaded by a common classloader. The same is true of any shared
  12. aspects.
  13. == Running AspectJ servlets in Tomcat 4.x
  14. In Tomcat, you can deploy application servlets in WAR's or in exploded
  15. web directories and share code across applications.
  16. . Use `ajc` to compile the servlets, and deploy the classes as usual
  17. into `{WebRoot}/WEB-INF/classes`.
  18. . If your web applications or aspects do not interact, deploy
  19. `aspectjrt.jar` into `{WebRoot}/WEB-INF/lib`.
  20. . If your web applications or aspects might interact, deploy them to
  21. `${CATALINA_BASE}/shared/lib`.
  22. Tomcat 4.x uses the Jasper engine based on Ant to compile JSP's. To set
  23. up ajc as the compiler, do the following before starting Tomcat:
  24. . Put `aspectjtools.jar` in `${CATALINA_HOME}/common/lib` so that it can
  25. be loaded by Jasper.
  26. . Update Jasper servlet parameters in `${CATALINA_HOME}/conf/web.xml` to
  27. tell Ant to use `ajc` by setting the compiler property to the AspectJ
  28. compiler adapter:
  29. +
  30. [source, xml]
  31. ....
  32. <servlet>
  33. <servlet-name>jsp</servlet-name>
  34. <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
  35. ...
  36. <init-param>
  37. <param-name>compiler</param-name>
  38. <param-value>org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter</param-value>
  39. </init-param>
  40. ....
  41. . The classpath is dynamically generated from the webapp deployment, so
  42. `aspectjrt.jar` should be in `{webapp}/WEB-INF/lib` or some shared or
  43. common directory supported by the server.
  44. . Alternatively, you can precompile JSP's using
  45. xref:../scripts/precompile-jsp.build.xml[this Ant script]. That involves
  46. manually updating the `web.xml` file with the `Jasper`-generated servlet
  47. mappings.