Version 3

    \ To set up the PojoCache in JBoss 4.0.5

    (Contributed by Reifsnyder)

     

    • Download and install JBoss 4.0.5. To install, double-click on the jems-installer-1.2.0.GA.jar and click Next through the installer. Choose ejb3-clustered when asked to choose an install type.

    • Download and unzip jboss-aop_1.5.2.GA.zip to get the underlying aspect-oriented programming code that JBoss uses to do caching.

      • Copy the jar files from the lib-50 directory to <your JBoss install directory>/server/default/lib.

      • Delete the file jboss-aop.jar (it is superceded by jboss-aop-jdk50.jar) from <your JBoss install directory>/server/default/lib.

      • Copy the /etc/base-aop.xml file to <your JBoss install directory>/server/default/deploy.

      • Copy the /jboss-40-install\jboss-aop-jdk50.deployer directory to <your JBoss install directory>/server/default/deploy and delete the jboss-aop.deployer folder from the server/default/deploy directory.

    • Download and unzip jboss-cache-dist-1.4.1.GA.zip, which contains the JBoss caching code.

      • Copy the jar files from the lib-50 directory to <your JBoss install directory>/server/default/lib.

      • Copy pojocache-service.xml from /etc/META-INF to <your JBoss install directory>/server/default/deploy. Edit this file: search for “DummyTxManagerLookup” and replace it with “JBossTransactionManagerLookup” in one place in this file.

      • Delete jboss-cache.jar from <your JBoss install directory>/server/default/lib.

    • Make the following changes in your code:

      • Add the annotation “@org.jboss.cache.aop.annotation.PojoCacheable” on the line directly above your class declaration.

      • Ensure that all class member variables are constructed using java primitive types (e.g., int, String, etc.); List, Map, or Set; or other POJOs that are serializable or PojoCacheable.

      • Include a get/set method for each member variable. This is just standard EJB 3.0 construction for a POJO.

    • Create a jboss-aop.xml file that will be used for the build that contains only the following code:

    <aop>    <prepare expr="field( @org.jboss.cache.aop.annotation.PojoCacheable->)" />    <prepare expr="field( $instanceof {@org.jboss.cache.aop.annotation.InstanceOfPojoCacheable}->)" /> </aop>

    • Create a jboss-aop.xml file that will be included in the META-INF directory of your ejb.jar file if the class has no subclasses:

    <aop>    <prepare expr="field( @mypackagename.myclassname->)" /> </aop>

         Or if the class has subclasses:

    <aop>    <prepare expr="field( $instanceof{@mypackagename.myclassname}->)" /> </aop>

         Include a prepare statement for each POJO that you want to cache.

     

    • Include a call to aopc (precompiler) in your build.xml script to precompile the classes for caching. You must also ensure that you delete all previously compiled versions of your classes (all .class files and jars/ears/wars that you reference that contain them) prior to attempting to precompile the aspectized POJOs!

     

    Here is the build.xml file for the Chat application:

    <?xml version="1.0"?> <!--Build file for PojoCache --> <project name="Caching" default="done" basedir=".">    <!-- Initialization of all property settings-->    <target name="init">       <property name="appname"        value="cache"   />       <property name="src.dir"        value= "." />         <property name="lib.dir"        value="lib"              />       <property name="ejb.dir"        value="ejb"              />       <property name="build.dir"      value="build"            />      <property name="cache.src.dir"   value="${src.dir}" />      <property name="cache.classes.dir"   value="${ejb.dir}" />                  <property name="oc4j.home" value="C:/Program Files/jboss-4.0.5.GA/server"/>      <property name="jboss.lib" value="C:/Program Files/jboss-4.0.5.GA/lib"/>      <property name="jboss.home" value="C:/Program Files/jboss-4.0.5.GA"/>       <property name="j2ee.home" value="${oc4j.home}\default\lib"/>      <property name="jboss.cache" value="C:/JBossCache-1.4.1.GA/lib-50"/>                  <path id="build.classpath">           <pathelement location="$"/>              <fileset dir="${jboss.home}/lib">                   <include name="/.jar"/>              </fileset>              <fileset dir="${oc4j.home}/default/lib">                   <include name="/.jar"/>              </fileset>              <fileset dir="${oc4j.home}/default/deploy/jboss-aop-jdk50.deployer">                   <include name=".jar"/>              </fileset>              <fileset dir="${src.dir}">                   <include name="/.jar"/>              </fileset> <!-- You must include Tomcat .sar in the build path for aopc           if it’s in your Jboss config  -->                    <fileset dir="${oc4j.home}/default/deploy/tc5-cluster.sar">                  <include name="tc5-cluster.aop" />              </fileset>              <pathelement location="${cache.classes.dir}"/>         </path>                     <taskdef name="aopc" classname="org.jboss.aop.ant.AopC"              classpathref="build.classpath"/>       </target>    <target name="prepare" depends="init">           <delete file="${oc4j.home}\server\deploy\chatserver.ear" />                 <!-- Get rid of the previously compiled             .class files and .jar, .war, .ear -->        <!-- This step is REQUIRED by aopc  -->        <delete dir="${lib.dir}/WEB-INF/classes"/>        <delete dir="${ejb.dir}"/>           <delete dir="${build.dir}"/>                 <!-- Make the directory structure we need -->       <mkdir dir="${lib.dir}" />       <mkdir dir="${ejb.dir}" />       <mkdir dir="${ejb.dir}/META-INF" />       <mkdir dir="${lib.dir}/WEB-INF" />       <mkdir dir="${lib.dir}/WEB-INF/classes" />       <mkdir dir="${build.dir}" />    </target>    <target name="classes" depends="prepare">         <!-- Compile your class files first -->         <javac srcdir="${src.dir} "              destdir="${ejb.dir}"              includes=".java"              classpath="${web.classpath}:${lib.dir}/WEB-INF/classes"                   debug="true"/>        <!-- Then run aopc to precompile the pojocacheable classes -->        <aopc compilerclasspathref="build.classpath" verbose="true">            <classpath path="build.classpath"/>            <src path="${cache.classes.dir}"/>             <include name="/ChatSubscriberValue.class"/>            <aoppath path="META-INF/jboss-aop.xml"/>     </aopc>    </target>    <target name="meta-inf" depends="prepare">         <!-- jboss-aop.xml reference -->         <copy file="${src.dir}/META-INF/jboss-aop.xml"           tofile="${ejb.dir}/META-INF/jboss-aop.xml" />             </target>    <!--jar up your files, deploy the jar, war, or ear --> </project>