November 15, 2010

Redeploy application to Weblogic Server through Ant script

The most time consuming task in a Web app development is to redeploy the application into the server for every change and test it.

In Weblogic Workshop IDE, we have an option to redeploy the app into Weblogic server by just right clicking it. But in Intellij Idea, I was not able to find such feature. We spent considerable amount of time to redeploy application using 'Weblogic Console' until we figured out the 'Ant' script to do it.

<project>
<property name="bea.home" value="C:/bea"/>
<property name="wl.home" value="${bea.home}/weblogic92"/>
<property name="wl.domain" value="domainName"/>
<property name="wl.server" value="serverName"/>
<!-- classpath to have weblogic.jar as the first jar -->
<path id="base.path">
<fileset file="${wl.home}/server/lib/weblogic.jar"/>
<fileset dir="${wl.home}/server/lib/">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${java.class.path}/"/>
</path>

<!-- weblogic tasks-->
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
<classpath refid="base.path"/>
</taskdef>
<taskdef name="wlserver" classname="weblogic.ant.taskdefs.management.WLServer">
<classpath refid="base.path"/>
</taskdef>

<target name="deployApp">
<wldeploy action="deploy" verbose="true" debug="true"
name="sampleApp" source="z:/app/target/sampleApp.ear"
user="weblogic" password="weblogic"
adminurl="t3://localhost:7001" targets="${wl.server}"/>
</target>

<target name="redeployApp">
<wldeploy action="undeploy" verbose="true" debug="true" name="sampleApp" 
user="weblogic" password="weblogic"
adminurl="t3://localhost:7001" targets="${wl.server}"/>
<wldeploy action="deploy" verbose="true" debug="true"
name="sampleApp" source="z:/app/target/sampleApp.ear"
user="weblogic" password="weblogic"
adminurl="t3://localhost:7001" targets="${wl.server}"/>
</target>
</project>

TIP:
Use SUBST command in Windows to map your project location to a new drive. For eg.,
subst z: d:/venky/projects/utils/sampleApp 

Individual developers in the team can checkout the code to any location but using this SUBST command will help the team to refer the project from same location like z:/src. Even though IDE's use relative path, it is nice to do this as the team can use these kinds of file without any customization.

No comments:

Post a Comment