<!-- ********************************************************************************** -->
<!-- Taks definitions -->
<!-- ********************************************************************************** -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${ant.lib.dir}/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>
<!-- ********************************************************************************** -->
<!-- startWeblogic --v
<!-- For remote access using ssh define the properties : -->
<!-- server-user -->
<!-- server-passwd -->
<!-- ********************************************************************************** -->
<target name="start-weblogic" description="Start weblogic">
<if>
<equals arg1="${server-host}" arg2="localhost" />
<then>
<echo message="__________ Check Weblogic" />
<if>
<available file="${weblogic.home.dir}/wlserver_10.3/server/lib/weblogic.jar"/>
<then>
<echo message="Weblogic server found" />
</then>
<else>
<fail message="No Weblogic server has been found" />
</else>
</if>
<echo message="__________ Check if libraries correctly installed" />
<echo message="__________ Stop Weblogic server if started" />
<antcall target="stop-weblogic" inheritrefs="true" />
<echo message="__________ Start Weblogic" />
<property name="weblogic.console" value="http://${server-host}:${server-adminPort}/console"/>
<if>
<not>
<http url="${weblogic.console}" />
</not>
<then>
<echo message="Weblogic is not running" />
<echo message="Starting Weblogic server..." />
<forget>
<exec executable="${weblogic.domain.dir}/bin/${start-admin-server}" dir="${weblogic.domain.dir}/bin" />
</forget>
<waitfor maxwait="2" maxwaitunit="minute" checkevery="100" checkeveryunit="millisecond">
<http url="${weblogic.console}" />
</waitfor>
<echo message="Weblogic started" />
</then>
<else>
<echo message="Weblogic server is already running" />
</else>
</if>
</then>
<else>
<sshexec host="${server-host}" username="${server-user}" password="${server-passwd}" command="${weblogic.domain.dir}/bin/${start-managed-server}" trust="yes" failonerror="no" />
<sleep seconds="60" />
</else>
</if>
</target>
<!-- ********************************************************************************** -->
<!-- stopWeblogic -->
<!-- For remote access using ssh define the properties : -->
<!-- server-user -->
<!-- server-passwd -->
<!-- ********************************************************************************** -->
<target name="stop-weblogic" description="Stop weblogic">
<if>
<equals arg1="${server-host}" arg2="localhost" />
<then>
<echo message="__________ Stop Weblogic" />
<property name="weblogic.console" value="http://${server-host}:${server-adminPort}/console"/>
<if>
<http url="${weblogic.console}" />
<then>
<echo message="Weblogic is running" />
<echo message="Stopping Weblogic server..." />
<forget>
<exec executable="${weblogic.domain.dir}/bin/${stop-admin-server}" dir="${weblogic.domain.dir}/bin" />
</forget>
<waitfor maxwait="2" maxwaitunit="minute" checkevery="100" checkeveryunit="millisecond">
<not>
<http url="${weblogic.console}" />
</not>
</waitfor>
<echo message="Weblogic stopped" />
</then>
<else>
<echo message="Weblogic server is already stopped" />
</else>
</if>
</then>
<else>
<sshexec host="${server-host}" username="${server-user}" password="${server-passwd}" command="${weblogic.domain.dir}/bin/${stop-managed-server}" trust="yes" failonerror="no" />
<sleep seconds="20" />
</else>
</if>
</target>
Define also some properties :
# Weblogic home dir and domain location # Variable only used to start and stop the server when localhost is used # in server location weblogic.home.dir=D:/weblogic.10.3.4 weblogic.domain.dir=D:/weblogic.10.3.4/user_projects/domains/YuuWaa # The command to run for starting and stoping web logic start-admin-server=startWebLogic.cmd stop-admin-server=stopWebLogic.cmd start-managed-server=startManagedWebLogic.cmd stop-managed-server=stopManagedWebLogic.cmd # Cluste name where to deploy cluster-name= # host and port of the listening admin console server-host=localhost server-adminPort=7001 # User/Password used when connecting to the admin console of WLS serverWL-adminuser=weblogic serverWL-adminpasswd=testpwd
