Table of Contents

Note: this is a temporary solution. Not very clean because aspects are global for all applications in the container. In the future, a better solution will be available.

Running JAsCo within an application server

Application servers are typically quite sensitive to out-of-the ordinary applications mainly because of specialized class loading strategies. Aspect Frameworks can thus experience problems when used inside an application server. JAsCo is no exception to this. In order to make JAsCo work in these kind of environments, special care has to be taken.

There are two options to run JAsCo inside an application server: either by using the preprocessor or by using HotSwap 2. The preprocessor (TransformBean) has the advantage that it is easier to set up, but is less flexible and generally also slower. HotSwap 2 on the other hand is faster and more flexible, but more error prone as run-time byte-code instrumentation is employed. The following two sections explain these two alternatives and uses Apache Tomcat as concrete example:

Using HotSwap 2

The following solution is no longer supported, it might or might not work for you, we are working to provide a better solution...

When running an application server using the JAsCo HotSwap framework, all classes are first pre-processed and afterwards altered to include aspect code when aspects are there. Watch out for:

For detailed information about HotSwap 2 and its options, consult the HotSwap2 guide.

For Apache Tomcat this means that you have to follow the following steps to run JAsCo using HotSwap2:

Note: This solution is only availble since 0.8 final (not the betas!)

Using the preprocessor tool

This solution is probably the most stable one but also the slowest performance wise.

When JAsCo should automatically detect connectors, use the following strategy:

  1. Transform all classes where aspects should be applicable using the transformBean tool.
  2. Make sure the jasco.jar and jasco-libs.jar are in the classpath of the application in the container.
  3. Make sure the compiled aspects are in the classpath of the application.
  4. place all compiled connectors in a directory <myConnectorDirectory> (name doesnt matter)
  5. init the connector load path from your application before doing anything else: jasco.options.Options.setConnectorLoadPath(<fullPathToMyConnectorDirectory>). IMPORTANT: make sure that the class that inits the connector load path is not transformed!
  6. Run the application server as usual. JAsCo will detect all connectors in the <myConnectorDirectory>. When connectors are added and removed, the corresponding aspects are added and removed dynamically as well.

When you want to load connectors from your application yourself, use the following strategy:

  1. Transform all classes where aspects should be applicable using the transformBean tool.
  2. Make sure the jasco.jar and jasco-libs.jar are in the classpath of the application in the container.
  3. Make sure the compiled aspects and compiled connectors are in the classpath of the application.
  4. Run the application server as usual. JAsCo will not load connectors automatically, in order to weave the aspects you have to load them manually as described below.

In order to manually add new connectors and their aspects at run-time, do the following:

jasco.Jasco.loadConnector(Connector.<classnameOfMyConnector>.getConnector());

Or when the connector is not yet compiled, but still in JAsCO source format:

jasco.Jasco.compileAndLoadConnector(<FullFileNameOfConnectorSource>);

(Javadoc of jasco.Jasco class: http://ssel.vub.ac.be/jasco/nightly/doc/jasco/Jasco.html