24 Ağustos 2011 Çarşamba

ant deploy to glassfish for service assemblies

The previous post is about ant deploy of web services to glassfish v2.1 application server. If you are curious, please read http://hilaltarakci.blogspot.com/2011/08/ant-deploy-to-glassfish.html.
This post is about deploying service assemblies to glassfish via ant..

Here is my solution:
jbi_admin.xml, copied from ${glassfish.home}/jbi/bin, modified as follows:


<?xml version="1.0" encoding="UTF-8"?>
<!--
 # BEGIN_HEADER - DO NOT EDIT
 #
 # The contents of this file are subject to the terms
 # of the Common Development and Distribution License
 # (the "License").  You may not use this file except
 # in compliance with the License.
 #
 # You can obtain a copy of the license at
 # https://open-esb.dev.java.net/public/CDDLv1.0.html.
 # See the License for the specific language governing
 # permissions and limitations under the License.
 #
 # When distributing Covered Code, include this CDDL
 # HEADER in each file and include the License file at
 # https://open-esb.dev.java.net/public/CDDLv1.0.html.
 # If applicable add the following below this CDDL HEADER,
 # with the fields enclosed by brackets "[]" replaced with
 # your own identifying information: Portions Copyright
 # [year] [name of copyright owner]
-->


<!--
 # @(#)jbi_admin.xml
 # Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
 #
 # END_HEADER - DO NOT EDIT
-->
<!--
 Copyright (c) 2004-2007 Sun Microsystems Inc., All Rights Reserved.
-->
<!--
@author chikkala
-->
<project basedir="." name="jbi_admin" xmlns:jbi="http://www.sun.com/ns/jbi/jbi-ant/1">
<target name="-pre-jbi-admin-setup">
</target>


<target name="-jbi-admin-setup" depends="-pre-jbi-admin-setup">
<taskdef resource="com/sun/jbi/ui/ant/antlib.xml" />
<!-- properties used as attribute values for ant tasks -->
<property name="jbi.target" value="server" />
<property name="jbi.secure" value="false" />
<property name="jbi.username" value="admin" />
<property name="jbi.password" value="adminadmin" />
<property name="jbi.host" value="localhost" />
<property name="jbi.port" value="4848" />
<property name="jbi.show.descriptor" value="false" />
<property name="jbi.task.fail.on.error" value="true" />
<property name="jbi.force.task" value="false" />
<property name="jbi.keep.archive" value="false" />
</target>


<target name="init-jbi-admin" depends="-jbi-admin-setup" />


<!-- deployment targets -->
<!-- deploy service assembly targets -->


<target name="-init-deploy-sa">
<condition property="deploy.sa">
<and>
<isset property="jbi.deploy.file" />
<not>
<isset property="jbi.service.assembly.name" />
</not>
</and>
</condition>
<condition property="deploy.sa.from.domain">
<and>
<isset property="jbi.service.assembly.name" />
<not>
<isset property="jbi.deploy.file" />
</not>
</and>
</condition>
<condition property="deploy.sa.option.error1">
<and>
<isset property="jbi.service.assembly.name" />
<isset property="jbi.deploy.file" />
</and>
</condition>
<condition property="deploy.sa.option.error2">
<and>
<not>
<isset property="jbi.service.assembly.name" />
</not>
<not>
<isset property="jbi.deploy.file" />
</not>
</and>
</condition>
</target>


<target name="-do-deploy-sa" depends="init-jbi-admin, -init-deploy-sa" if="deploy.sa">
<jbi-deploy-service-assembly username="${jbi.username}" password="${jbi.password}" secure="${jbi.secure}" host="${jbi.host}" port="${jbi.port}" target="${jbi.target}" 
failOnError="${jbi.task.fail.on.error}" file="${jbi.deploy.file}" />
</target>


<target name="-do-deploy-sa-from-domain" depends="init-jbi-admin, -init-deploy-sa" if="deploy.sa.from.domain">
<jbi-deploy-service-assembly username="${jbi.username}" password="${jbi.password}" secure="${jbi.secure}" host="${jbi.host}" port="${jbi.port}" target="${jbi.target}" 
failOnError="${jbi.task.fail.on.error}" name="${jbi.service.assembly.name}" />
</target>


<target name="-do-deploy-sa-option-error1" depends="init-jbi-admin, -init-deploy-sa" if="deploy.sa.option.error1">
<jbi-deploy-service-assembly username="${jbi.username}" password="${jbi.password}" secure="${jbi.secure}" host="${jbi.host}" port="${jbi.port}" target="${jbi.target}" 
failOnError="${jbi.task.fail.on.error}" file="${jbi.deploy.file}" name="${jbi.service.assembly.name}" />
</target>


<target name="-do-deploy-sa-option-error2" depends="init-jbi-admin, -init-deploy-sa" if="deploy.sa.option.error2">
<jbi-deploy-service-assembly username="${jbi.username}" password="${jbi.password}" secure="${jbi.secure}" host="${jbi.host}" port="${jbi.port}" target="${jbi.target}" 
failOnError="${jbi.task.fail.on.error}" />
</target>


<!-- main install target for deploy service assembly -->
<target name="deploy-service-assembly" depends="init-jbi-admin, -init-deploy-sa,
        -do-deploy-sa, -do-deploy-sa-from-domain, 
        -do-deploy-sa-option-error1, -do-deploy-sa-option-error2" description="Deploys Service assembly">
</target>


<!-- undeploy service assembly target -->
<target name="-init-undeploy-sa" depends="init-jbi-admin">
<!-- default service assembly name value. null or empty for no service assembly dependency in query tasks-->
<property name="jbi.service.assembly.name" value="" />
</target>


<target name="undeploy-service-assembly" depends="init-jbi-admin, -init-undeploy-sa" description="Undeploys service assembly">
<jbi-undeploy-service-assembly username="${jbi.username}" password="${jbi.password}" secure="${jbi.secure}" host="${jbi.host}" port="${jbi.port}" target="${jbi.target}" 
failOnError="${jbi.task.fail.on.error}" force="${jbi.force.task}" keepArchive="${jbi.keep.archive}" name="${jbi.service.assembly.name}" />
</target>


<target name="-init-sa-lifecycle-options" depends="init-jbi-admin">
<!-- default service assembly name value. null or empty for no service assembly dependency in query tasks-->
<property name="jbi.service.assembly.name" value="" />
</target>


<!-- start service assembly target -->
<target name="start-service-assembly" depends="init-jbi-admin, -init-sa-lifecycle-options" description="starts service assembly">
<jbi-start-service-assembly username="${jbi.username}" password="${jbi.password}" secure="${jbi.secure}" host="${jbi.host}" port="${jbi.port}" target="${jbi.target}" 
failOnError="${jbi.task.fail.on.error}" name="${jbi.service.assembly.name}" />
</target>


<!-- stop service assembly target -->
<target name="stop-service-assembly" depends="init-jbi-admin, -init-sa-lifecycle-options" description="stops service assembly">
<jbi-stop-service-assembly username="${jbi.username}" password="${jbi.password}" secure="${jbi.secure}" host="${jbi.host}" port="${jbi.port}" target="${jbi.target}" 
failOnError="${jbi.task.fail.on.error}" name="${jbi.service.assembly.name}" />
</target>


<!-- shutdown service assembly target -->
<target name="shut-down-service-assembly" depends="init-jbi-admin, -init-sa-lifecycle-options" description="shuts down service assembly">
<jbi-shut-down-service-assembly username="${jbi.username}" password="${jbi.password}" secure="${jbi.secure}" host="${jbi.host}" port="${jbi.port}" target="${jbi.target}" 
failOnError="${jbi.task.fail.on.error}" force="${jbi.force.task}" name="${jbi.service.assembly.name}" />
</target>


</project>

and the actual build.xml is as follows:

<?xml version="1.0"?>
<project name="myproject" default="zip" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:cs="antlib:com.puppycrawl.tools.checkstyle">


<import file="./jbi_admin.xml" />
        <!-- some stuff deleted.. -->
<!-- ==================================== -->
<!-- Glassfish tasks                      -->
<!-- ==================================== -->
<target name="glassfish-init" unless="glassfish.initialized">
<path id="jbi.ant.tasks.classpath.id">
<pathelement location="${glassfish.home}/lib/sun-appserv-ant.jar" />
<pathelement location="${glassfish.home}/jbi/lib/jbi-ant-tasks.jar" />
</path>
<!-- Load jbi task definitions -->
<taskdef resource="com/sun/jbi/ui/ant/antlib.xml" classpathref="jbi.ant.tasks.classpath.id" />
<taskdef name="unset" classname="ise.antelope.tasks.Unset">
<classpath path="${build.lib}/antelopetasks-3.2.10.jar" />
</taskdef>
<!-- ensure that glassfish taskdef is only run once, otw ant will error -->
<property name="glassfish.initialized" value="true" />
</target>


<target name="glassfish-password-init" depends="init, glassfish-init">
<!-- do not forget to delete this! -->
<echo message="AS_ADMIN_PASSWORD=adminadmin" file="${build.dir}/password.file" />
</target>


<target name="glassfish-prod-deploy-pre" depends="glassfish-init">
<!--<property name="jbi.service.assembly.name" value="" />-->
<unset name="jbi.service.assembly.name"/>
<property name="jbi.task.fail.on.error" value="true" />
<property name="jbi.host" value="${prod.host}" />
<property name="jbi.deploy.file" value="${build.dir}/${name}-${SURUM}.zip" />
</target>


<target name="glassfish-start-assembly-pre" depends="glassfish-init">
<property name="jbi.task.fail.on.error" value="true" />
<property name="jbi.service.assembly.name" value="${name}-${SURUM}" />
<property name="jbi.host" value="${prod.host}" />
<unset name="jbi.deploy.file"/>
<!--<property name="jbi.deploy.file" value="" />-->
</target>


<target name="glassfish-prod-undeploy-pre" depends="glassfish-init">
<property name="jbi.task.fail.on.error" value="false" />
<property name="jbi.service.assembly.name" value="${name}-${SURUM}" />
<property name="jbi.host" value="${prod.host}" />
<unset name="jbi.deploy.file"/>
<!--<property name="jbi.deploy.file" value="" />-->
</target>


<target name="exec-glassfish-prod-deploy" depends="zip, glassfish-prod-deploy-pre, deploy-service-assembly">
</target>


<target name="exec-glassfish-start-assembly" depends="glassfish-start-assembly-pre, start-service-assembly">
</target>


<target name="glassfish-prod-deploy" depends="exec-glassfish-prod-deploy, exec-glassfish-start-assembly">
</target>


<target name="glassfish-prod-undeploy" depends="glassfish-prod-undeploy-pre, shut-down-component, undeploy-service-assembly">
</target>


</project>


glassfish-prod-deploy target deploys the specified assembly to the application server and starts it.
Likewise, glassfish-prod-undeploy target shutdowns the assembly and undeploys it.

Hiç yorum yok:

Yorum Gönder