It'll be about JBoss Application Server and Aspect Oriented Programming and web applications.
As everyone who knows me know I develop simple, yet powerful web application. At least I try. There was time at the beginning of this adventure I've used Tomcat web container among with Struts Model-View-Controller framework.
After some time, Aspect Oriented Programming (thanks to Andrew) came into my developer's life. It is JBoss AOP that I 'play' with.
I still need to develop web application. How to include AOP into web application? First of all I decided not to play with Tomcat any more. Main reason is I knew JBoss Application Server also has Tomcat embedded inside it. Also JBoss AS, as the JBoss company is the mother of JBoss AOP, has AOP included inside their product.
So I took the freshest JBoss 4.0.1 release of JBoss AS and unpacked it.
I use Ant for my application, so examples will use it. This "tutorial" is also valid for Java 1.4 version. I don't know if there are any problems with 1.5.
I assume you know basics of JBoss AOP and how to deploy [Struts] web application on Tomcat.
Steps to successfully deploy AOP enabled web application on JBoss AS with Struts:
I mean get your *.war file that was running on Tomcat with Struts. I had to change nothing to the files.
Here's solution: name each config file as: jboss-aop.xml and put it
into custom, _empty_ JAR file. Call JAR archive whatever
you want. Put those configuration archives into classpath and your'e done.
This way I'm able to write aspect libraries using JBossAOP and
plain Tomcat web server. :-)
Libraries needed to compile aspects are in these directories:
compile all sources, including aspects with plain Java compiler (I use <javac>)
<target name="pat_annotationc" depends="compile">
<taskdef name="annotationc"
classname="org.jboss.aop.ant.AnnotationC" classpathref="compile_classpath"/>
<annotationc compilerclasspathref="run_classpath"
classpathref="run_classpath"
bytecode="true">
<src path="src/"/>
<include name="**/*.java" />
</annotationc>
</target>
<target name="pat_aopc" depends="pat_annotationc">
<taskdef name="aopc"
classname="org.jboss.aop.ant.AopC" classpathref="compile_classpath" />
<aopc compilerclasspathref="run_classpath"
classpathref="run_classpath"
verbose="false">
<classpath path="run_classpath" />
<src path="${build.classes.dir}" />
<aoppath path="${etc.dir}/" />
</aopc>
</target>
So, basically, all we need is to pack all files related to web application into application.war file, and all files related to AOP into application.aop file. After doing this, put those two files into one file application.sar with one configuration file.
So here is how the structure of my deploy/ directory looks like:
/application.sar/
/META-INF:
jboss-service.xml
/application.aop/
/META-INF:
jboss-aop.xml
/application.war/
/WEB-INF:
/classes:
/org:
/nthx/
/prevayler/:
*.class, *MethodInvocation*.class
/lib:
ant.jar, log4j-1.2.8.jar, javax.servlet.jar, ...
/dtds/
/tlds/
struts-config.xml
tiles-defs.xml
validation.xml
validator-rules.xml
web.xml
/images:
book.png, ...
/includes:
inc-footer-links.jsp, ...
/pages:
index.jsp, ...
As you also see I've unpacked contents of all archives into directories with the same name. Though I believe it's not necessary.
The contents of jboss-service.xml is simply:
<?xml version="1.0" encoding="UTF-8"?>
<server>
</server>
We have to choices here: if we precompile sources with <aopc>, <annotationc> (as it is in my situation) then we do nothing and go to the next step
Otherwise we may not precompile sources using those two tasks!
Aspects may be hot deployed. But for this, one must adapt configuration:
Change
JBOSS_HOME/server/default/deploy/jboss-aop.deployer/META-INF/jboss-service.xml
and set variable EnableTransformer to true
For my needs I also update -Xmx value in run.conf file
I hope it helped you :)
Any questions, feedback.. put below.
One just needs to precompile AOP'ed sources with JBossAOP compiler (using Ant's tasks) and pack application (WAR) in a standard way.
I don't utilize JSP AOP precompilation, as I don't need aspects there and there is no Java code on my presentation layer webpages.