Wednesday, July 3, 2013

Dynamically Build and Deploy Java code without server start up - Hotswap

Hotswap enables developer to build and deploy the changes dynamically without server restart. It reduces development time and maximizes productiveness.

The server can be any (Jboss,Weblogic etc). It works very well for ATG and even to java application.

Configure Hotswap to build.xml


Step 1 

Download Hotswap.jar from google.


Step2

Copy the Hotswap to project lib folder.


Step 3 

Add the following target to build.xml


<taskdef name="hotswap" classname="dak.ant.taskdefs.Hotswap">
         <classpath path="C:\Project\lib\hotswap.jar" />
         </taskdef>



<target name="hotswap" depends="init">
            <tstamp>
                    <format property="class.tstamp" pattern="MM/dd/yyyy kk:mm:ss" />
            </tstamp>
   
            <property name="buildclasspath" refid="build.classpath" />
            <echo message="Compiling classes using classpath ${buildclasspath}" />
            <javac  srcdir="
C:\Project\src\main\java"
                    destdir="
C:\Project\gen\main\classes"
                    includes="**/*.java"
                    debug="on"
                    optimize="off"
                    source="${java.source.version}">
                    <classpath refid="build.classpath" />
            </javac>
            <hotswap verbose="true" port="8453">
                    <fileset dir="
C:\Project\gen\main\classes\" includes="**/*.class">
                            <date datetime="${class.tstamp}" pattern="MM/dd/yyyy kk:mm:ss"              when="after" granularity="0"/>
                    </fileset>
            </hotswap>
      </target>


 Done

 Make any changes to java file and build the project . the changes will be automatically deployed to server.





1 comment: