Wednesday, June 5, 2013

Attacking the legacy code:Buiding weblogic beehive application using ANT

Recently I started to investigate on writing an Ant script to build our J2EE web application. Right now we just export the WAR file using Eclipse IDE, but we plan to adopt Jenkins for the build automation, then we got a problem. I tried Eclipse Headless build, it did not working. So I decided to use Ant script to build our J2EE web application. Our application is based on Weblogic 10.3, it uses lots of weblogic portal library, netUI, and page flow. Through several times trial and error, finally I got my ant script works. It is a kind of tricky, here I would like to share my experience, show you how to write an ANT script to build the Weblogic beehive application.

1. Setup the environment variables in your ANT script file
 You need to setup following environment variables: WL_HOME, WORKSHOP_HOME, and BEA_HOME.
 In my computer weblogic was installed under C:\Oracle\Middleware, so these environment variables will look like this in my build.xml:

        <property environment="env"/>
<property name="env.WL_HOME" value="C:/Oracle/Middleware/wlserver_10.3"/>
<property name="env.WORKSHOP_HOME" value="C:/Oracle/Middleware/wlportal_10.3/workshop" />
<property name="env.BEA_HOME" value="C:/Oracle/Middleware" />

2. Import weblogic Ant task files into build.xml
   Based on this article, WebLogic Server ships with the following Ant files for building and deploying Beehive applications:
   <WL_HOME>\workshop\weblogic-beehive\ant\weblogic-beehive-buildmodules.xml
   <WL_HOME>\workshop\weblogic-beehive\ant\weblogic-beehive-tools.xml
   <WL_HOME>\workshop\weblogic-beehive\ant\weblogic-beehive-imports.xml
 
   In my computer, the ant script folder will be: C:\Oracle\Middleware\wlportal_10.3\workshop\weblogic-beehive\ant

   I found a bug, in weblogic-beehive-imports.xml:
 
   <property name="apache.xbean.jar" value="${env.BEA_HOME}/modules/com.bea.core.xml.xmlbeans_1.0.0.0_2-4-1.jar"/>
   <property name="bea.xbean.jar" value="${env.BEA_HOME}/modules/com.bea.core.xml.beaxmlbeans_1.0.0.0_2-4-1.jar"/>

   should be changed to:

   <property name="apache.xbean.jar" value="${env.BEA_HOME}/modules/com.bea.core.xml.xmlbeans_1.1.0.0_2-4-1.jar"/>
   <property name="bea.xbean.jar" value="${env.BEA_HOME}/modules/com.bea.core.xml.beaxmlbeans_1.1.0.0_2-4-1.jar"/>

   I just copied those 3 xml file into my project folder, so in my build.xml, add following after the property definition:
 
   <import file="weblogic-beehive-imports.xml"/>
   <import file="weblogic-beehive-tools.xml"/>
   <import file="weblogic-beehive-buildmodules.xml"/>

3. Write ant target to build web application
   Use weblogic "build-webapp" ant task, it will compile the source code, and it will generate the page flow xml, specifically it will generate those xml files under WEB-INF\classes\_pageflow folder, which took me a long time to figure out.
    Please note: to build successfully, you need to put the source code under the WEB-INF\src folder.
 
   The ant target will look like this:

   <target name="build-web" depends="init">
<build-webapp
     webapp.src.dir="${build.dir}"
     webapp.build.dir="${build.dir}"
     app.build.classpath="webapp.classpath"/>
   </target>   
 
4. "Error running apt compiler" issue
   At first the ant script works in my local machine, but under windows server it failed with "Error running apt compiler", and the detailed error is like "CreateProcess error=87". After Google this error, and found out it is because the classpath is too long.
   To fix this, I checked my classpath library, and removed all the unnecessary files, and finally it is working.

Resource
1.  Building Beehive Applications

2 comments:

  1. Useful post on j2ee Buiding weblogic beehive application using ANT...thanks for sharing.

    ReplyDelete
  2. We got stuck with error mentioned in point 4. We are unable to resolve it. Pls help

    ReplyDelete