环境Glassfish2.x ,windows 7 或者 windows server 2008
该脚本能够部署,关闭和启动glassfish服务。
注意的是,启动时glassfish2有一个bug,必须设置系统环境变量OLD_LAUNCHER为true (如果本来没有就添加一个)
官方文档参考:
http://docs.oracle.com/cd/E19316-01/820-4336/6nfqd2b2e/index.html
下面贴脚本了,
<project name="MyDeploy" default="dist" basedir=".">
<description>
Deploying web application on GlassFish2.x
</description>
<!-- set global properties for this build -->
<property name="glassfish.host" value="127.0.0.1" />
<property name="glassfish.user" value="admin" />
<property name="glassfish.passwordfile" location="pwd" />
<!-- password file is a text file with line: AS_ADMIN_PASSWORD=[i]your_glassfish_admin_password[/i] -->
<property name="glassfish.deployer.dir" value="c:/portal/glassfish" /> <!--here use your directory -->
<property name="warfile" value="d:/your.war"/>
<property name="webapp.name" value="yourweb"/>
<property name="webapp.context" value="yourweb"/>
<path id="glassfish.deployer">
<fileset dir="${glassfish.deployer.dir}\lib" >
<include name="*.jar"/>
</fileset>
</path>
<target name="deploy" description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<taskdef
name="sun-appserv-deploy"
classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.DeployTask"
classpathref="glassfish.deployer" />
<taskdef
name="sun-appserv-undeploy"
classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.UndeployTask"
classpathref="glassfish.deployer" />
<taskdef
name="sun-appserv-admin"
classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.AdminTask"
classpathref="glassfish.deployer" />
<target name="glassfish-stop">
<echo level="info"> Begin to stop glassfish server now! </echo>
<sun-appserv-admin asinstalldir="${glassfish.deployer.dir}" explicitcommand="stop-domain domain1">
<server
host="${glassfish.host}"
user="${glassfish.user}"
passwordfile="${glassfish.passwordfile}" />
</sun-appserv-admin>
<echo level="info"> done! </echo>
<tstamp>
<format property="end_time" pattern="yyyy-MM-dd HH:mm:ss.SSS" locale="pl"/>
</tstamp>
<echo level="info">Glassfish stopped at ${end_time}</echo>
</target>
<target name="glassfish-start">
<echo level="info"> Begin to start glassfish server now! </echo>
<sun-appserv-admin asinstalldir="${glassfish.deployer.dir}" explicitcommand="start-domain domain1">
<server
host="${glassfish.host}"
user="${glassfish.user}"
passwordfile="${glassfish.passwordfile}" />
</sun-appserv-admin>
<echo level="info"> done! </echo>
<tstamp>
<format property="end_time" pattern="yyyy-MM-dd HH:mm:ss.SSS" locale="pl"/>
</tstamp>
<echo level="info">Glassfish started at ${end_time}</echo>
</target>
<target name="glassfish-deploy" >
<echo level="info">Deploing WAR file on the glassfish remote server ... </echo>
<sun-appserv-deploy
file="${warfile}"
name="${webapp.name}"
contextroot="${webapp.context}"
upload="false"
force="true"
verify="false"
precompilejsp="false"
asinstalldir="${glassfish.deployer.dir}" >
<server
host="${glassfish.host}"
user="${glassfish.user}"
passwordfile="${glassfish.passwordfile}" />
</sun-appserv-deploy>
<echo level="info"> done! </echo>
<tstamp>
<format property="end_time" pattern="yyyy-MM-dd HH:mm:ss.SSS" locale="pl"/>
</tstamp>
<echo level="info">WAR file deployed at ${end_time}</echo>
</target>
<target name="glassfish-undeploy" >
<sun-appserv-undeploy
name="${webapp.name}"
asinstalldir="${glassfish.deployer.dir}">
<server
host="${glassfish.host}"
user="${glassfish.user}"
passwordfile="${glassfish.passwordfile}" />
</sun-appserv-undeploy>
</target>
</project>
GlassFish 3.1.2 web profile要安装一个模块:glassfish-ant-tasks