aboutsummaryrefslogtreecommitdiffstats
path: root/docs/sandbox/trails/j2ee.html
blob: 804f4343167f3abff0b3a5a6693be50605d4da8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<html>
<body>

This contains short notes on using AspectJ with various J2EE
servers and deployment tools.

<!-- @author Wes Isberg -->

<h3>Using AspectJ in servlets</h3>
<h4>Generally</h4>
<!-- START-SAMPLE j2ee-servlets-generally Using AspectJ in servlets -->
AspectJ programs work if run in the same namespace and with aspectjrt.jar.
Servlet runners and J2EE web containers should run AspectJ programs fine
if the classes and required libraries are deployed as usual.  

As with any shared library, if more than one application is using AspectJ, 
then the aspectjrt.jar should be deployed where it will be loaded by a 
common classloader. The same is true of any shared aspects.

<!-- END-SAMPLE j2ee-servlets-generally  -->

<h4>Running AspectJ servlets in Tomcat 4.x</h4>

<!-- START-SAMPLE j2ee-tomcat4-servlets Running AspectJ servlets in Tomcat 4.x -->
In Tomcat, you can deploy application servlets in WAR's 
or in exploded web directories and share code across
applications.
<ol>  
<li>Use <code>ajc</code> to compile the servlets, 
    and deploy the classes as usual into
    <code>{WebRoot}/WEB-INF/classes</code>.
    </li>

<li>If your web applications or aspects do not interact, deploy
    <code>aspectjrt.jar</code> into
    <code>{WebRoot}/WEB-INF/lib</code>.
    </li>
<li>If your web applications or aspects might interact, deploy
    them to <code>${CATALINA_BASE}/shared/lib</code>.
    </li>
</ol>  
<!-- END-SAMPLE j2ee-tomcat4-servlets  -->

<!-- START-SAMPLE j2ee-tomcat4-jsp Running AspectJ JSP's in Tomcat 4.x -->
Tomcat 4.x uses the Jasper engine based on Ant to compile JSP's.
To set up ajc as the compiler, do the following before starting Tomcat:
<ol>  
<li>Put <code>aspectjtools.jar</code> in
<code>${CATALINA_HOME}/common/lib</code> so that it can be loaded
by Jasper.
</li>
<li>Update Jasper servlet parameters in
  <code>${CATALINA_HOME}/conf/web.xml</code> to tell Ant to use
  <code>ajc</code> by setting the compiler property to the
  AspectJ compiler adapter:
  <pre>
    &lt;servlet>
        &lt;servlet-name>jsp&lt;/servlet-name>
        &lt;servlet-class>org.apache.jasper.servlet.JspServlet&lt;/servlet-class>
        ...
        &lt;init-param>
            &lt;param-name>compiler&lt;/param-name>
            &lt;param-value>org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter&lt;/param-value>
        &lt;/init-param>
	</pre>
</li>
<li>The classpath is dynamically generated from the webapp deployment,
so <code>aspectjrt.jar</code> should be in 
<code>{webapp}/WEB-INF/lib</code> or some shared or common
directory supported by the server.
</li>

<li>Alternatively, you can precompile JSP's using 
<a href="#j2ee-tomcat4-precompileJsp">this Ant script</a>.
That involves manually updating the <code>web.xml</code> file 
with the <code>Jasper</code>-generated servlet mappings.
</li>
</ol>
<!-- END-SAMPLE j2ee-tomcat4-jsp -->

</body>
</html>