Wednesday, April 24, 2013

Integrate SubVersion+Hudson+Ant+Oracle Weblogic Server

In this post , we will see how to integrate SVN Server(Collabnet),CI Server(Hudson),Build Management Tool(Ant) and finally an Application Server(Oracle Weblogic J2EE Server). So to know more about how these components glued together all around the projects just keep reading.
Purpose of Components:
  1. SVN Server – The one which holds the various revisions of developer’s code
  2. CI Server – The one which perform builds
  3. Build Management Tool – The tool that helps CI Server to manage the project like class compilation, Bundling Jars,Wars,Ears
  4. Application Server – A single place where developer’s written Servlets, EJB and Web Services  survives 


Steps Involved:
1]Installed a Local CSVN and created a separate repository for your Application
2] Installed a Hudson(CI Server) and Created a job(App1-build) to do the bundling part
3] Created a build.xml to do the compiling and Bundling Part
4] Deployed the Bundled war file to one of our Local application Server

Step 1: Installed a Local CSVN and created a separate repository for App-Portal Application
image
Step 2: Installed a Hudson(CI Server) and Created a job(App1-build) to do the bundling part
image

Step 3: Created a build.xml to do the compiling and Bundling Part
<?xml version="1.0" encoding="UTF-8"?>
<project name="App1" default="All" basedir="."> 
  <!-- Define the properties used by the build -->
  <property name="app.name"        value="App1"/>
  <property name="tomcat.home"     value="${basedir}/lib/tomcat-lib" />
  <property name="struts.home"     value="${basedir}/lib/struts-lib" />
  <property name="hibernate.home"  value="${basedir}/lib/hibernate-lib" />
  <property name="axis2.home"      value="${basedir}/lib/axis-lib" />
  <property name="poi.home"        value="${basedir}/lib/pom-lib" />
  <property name="mysql.home"      value="${basedir}/lib/mysql-lib" />
  <property name="log4j.home"      value="${basedir}/lib/log4j-lib" />
  <property name="work.home"       value="${basedir}/work"/>
  <property name="dist.home"       value="${basedir}/dist"/>
  <property name="src.home"        value="${basedir}/src"/>
  <property name="web.home"        value="${basedir}/WebContent"/>
   <!-- Define the CLASSPATH -->
  <path id="compile.classpath">
    <fileset dir="${tomcat.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${struts.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${hibernate.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${axis2.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${poi.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${log4j.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${mysql.home}">
      <include name="*.jar"/>
    </fileset>
  </path>
  <target name="All" depends="init,compile,dist" description="Clean work dirs, then compile and create a WAR"/>
  <target name="init">
    <mkdir dir="build/classes"/>
    <mkdir dir="dist" />
  </target>
  <target name="clean" description="Delete old work and dist directories">
    <delete dir="${work.home}"/>
    <delete dir="${dist.home}"/>
  </target>

  <target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
    <mkdir  dir="${dist.home}"/>
    <mkdir  dir="${work.home}/WEB-INF/classes"/>
    <!-- Copy static HTML and JSP files to work dir -->
    <copy todir="${work.home}">
      <fileset dir="${web.home}"/>
    </copy>
  </target>

  <target name="compile" depends="prepare"
          description="Compile Java sources and copy to WEB-INF/classes dir">
    <javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes" debug="true" debuglevel="lines,vars,source">
    <classpath refid="compile.classpath"/>
    </javac>
     <copy  todir="${work.home}/WEB-INF/classes">
      <fileset dir="${src.home}" excludes="**/*.java"/>
    </copy>
    <copy  todir="${work.home}/WEB-INF/lib">
      <fileset dir="${tomcat.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${struts.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${hibernate.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${axis2.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${poi.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${log4j.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${mysql.home}">
      <include name="*.jar"/>
    </fileset>
    </copy>
  </target>

  <target name="dist" depends="compile"
          description="Create WAR file for binary distribution">
    <war destfile="${dist.home}/App1.war">
         <fileset dir="${work.home}"/>
         <lib dir="${work.home}/WEB-INF/lib"/>
         <classes dir="${work.home}/WEB-INF/classes"/>
    </war>
  </target>
</project> 

Step 4: Deployed the Bundled war file to one of our Local application Server
Application Deployed successfully,that's reason it's gone to active state. We can put the same war file in any Application Server Container(Apache Tomcat, Glass Fish,Oracle Weblogic,JBoss or Web Sphere), the procedure remains same.

image

Please let us know if have any issues in integrating SVN Server(Collabnet),CI Server(Hudson),Build Management Tool(Ant) and your Application Server :)

No comments:

Post a Comment