Logo
StartDownloadsDocumentationPublicationsContactCommunityDevelopers

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:

  • Enable the JAsCo application server mode (-Djasco.hotswap.applicationserver=true)
  • In general, it is not a good idea to apply aspects to the application server classes themselves, only apply aspects to application classes. So it is highly recommended to put them in the JAsCo excluded types by using the -Djasco.hotswap.excludedtypes option!
  • Another gotcha is that all aspects and connectors have to be in the classpath of the application server, not in the classpath of individual applications!
  • Likewise, the jasco jars (jasco.jar and jasco-libs.jar) have to be in the classpath of the application server as well.
  • Also make sure that the current directory (.) is in the classpath of the application server as well.

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:

  • Alter the catalina.bat or catalina.sh file located in the bin folder of your application server and include the following:
    • add -javaagent:E:\programs\JAsCo\jasco.jar to JAVA_OPTS (HotSwap 2 startup command)
    • add -Djasco.hotswap.applicationserver=true to JAVA_OPTS (HotSwap 2 compaibility with application servers mode)
    • add -Djasco.hotswap.excludedtypes=org.* to JAVA_OPTS (exclude tomcat classes from pre-processing)
    • add jasco.jar and jasco-libs.jar to CLASSPATH
    • add the jar files of aspects and class folders of connectors (connectors are always in folders, never in jars!) to CLASSPATH
    • add “.” to classpath (current directory)
  • Make sure to place all aspects and connectors in class folders visible to the application server (the ones you added to CLASSPATH). When using dynamic AOP, compile the connectors and aspects into these folders.
  • Done, when starting tomcat, the JAsCo framewok is initialized and JAsCo AOP should work!

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

documentation/ap.txt · Last modified: 25.04.2007 20:11 by wvdperre
SiteMapRecent Content by SSEL ©2002-2005     Latest JAsCo Release: JAsCo 0.8.7 (revised 2005-11-25 16:29:02)