如何使用Ant任务启动和停止jboss服务器?

时间:2010-06-17 08:29:12

标签: ant jboss

我需要停止,部署我的ear文件并使用Ant任务启动Jboss服务器。

我能够使用Ant任务成功地将我的J2EE应用程序作为ear文件编译,构建和部署到JBoss服务器中。我们可以在jboss控制台中看到我的应用程序的重新部署。我想在部署之前停止服务器并启动服务器。

有没有办法做到这一点?

3 个答案:

答案 0 :(得分:4)

这里是如何启动/停止JBoss应用程序容器,包括部署应用程序:

<!-- Stop Jboss -->
<target name="stop-jboss" description="Stops back-end EJB container" >
    <exec executable="${jboss.bin.dir}/shutdown.bat" spawn="true">
        <arg line="-S" />
    </exec>
    <echo>+-----------------------------+</echo>
    <echo>| J B O S S   S T O P P E D   |</echo>
    <echo>+-----------------------------+</echo>
</target>

<!-- Start Jboss -->
<target name="start-jboss" description="Starts back-end EJB container" >
    <exec executable="${jboss.bin.dir}/run.bat" spawn="true">
    </exec>
    <echo>+-----------------------------+</echo>
    <echo>| J B O S S   S T A R T E D   |</echo>
    <echo>+-----------------------------+</echo>
</target>

<!-- deploy target-->
<target name="deploy-war" description="deploy war file" depends="prepare">
  <sequential>
    <antcall target="stop-jboss" />
    <war destfile="${file.name}" webxml="conf/web.xml">
       <classes dir="bin" />
    </war>
    <antcall target="start-jboss" />
        <echo>+----------------------------+</echo>
        <echo>|   W A R  D E P L O Y E D   |</echo>
        <echo>+----------------------------+</echo>
  </sequential>
</target>

希望这有用:)

答案 1 :(得分:0)

Cargo支持ANT,旨在支持多个J2EE容器

答案 2 :(得分:0)

适当的os独立答案将是这样的:

<property name="my.jboss.home" value="/path/to/jboss/install/dir" />
<property name="my.jboss.host" value="localhost" />
<property name="my.jboss.port" value="9999" />
<property name="my.jboss.name" value="my-jboss-instance" />
<property name="my.jboss.debugport" value="8787" />

<!-- supposedly this is built by a seperate task -->
<property name="my.deployment" value="${basedir}/build/deployment.ear" />

<!-- starting preset -->
<presetdef name="start-jboss-preset">
    <java jar="${jboss.home}/jboss-modules.jar" fork="true" taskname="${jboss.name}">
        <jvmarg value="-server" />
        <jvmarg value="-Xms1024m" />
        <jvmarg value="-Xmx1024m" />
        <jvmarg value="-Dorg.jboss.boot.log.file=${jboss.home}/standalone/log/server.log" />
        <jvmarg value="-Dlogging.configuration=file:${jboss.home}/standalone/configuration/logging.properties" />
        <arg line="-mp ${jboss.home}/modules/ -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone" />
        <jvmarg value="-Djboss.home.dir=${jboss.home}" />
        <arg value="-b=localhost" />
        <arg value="-c=standalone-full.xml" />
        <jvmarg value="-Djboss.node.name=${jboss.name}" />
    </java>
</presetdef>

<!-- internal task to actually start jboss -->
<target name="start-jboss">
    <start-jboss-preset />
</target>

<!-- internal task to start jboss in debug mode -->
<target name="start-jboss-debug">
    <start-jboss-preset taskname="dbg:${jboss.name}:${jboss.debugport}">
        <jvmarg value="-agentlib:jdwp=transport=dt_socket,address=${jboss.debugport},server=y,suspend=n" />
    </start-jboss-preset>
</target>

<!-- preset to run jboss-cli, this can be used to push any command to a running
     jboss instance -->
<presetdef name="jboss-cli">
    <java jar="${jboss.home}/jboss-modules.jar" fork="true">
        <arg line="-mp ${jboss.home}/modules org.jboss.as.cli" />
        <arg value="--controller=${jboss.host}:${jboss.port}" />
        <arg value="--connect" />
    </java>
</presetdef>

<!-- the actual shut down command -->
<target name="exec-jboss">
    <jboss-cli failonerror="true">
        <arg value="${jboss.command}" />
    </jboss-cli>
</target>

<!-- public targets with your properties set -->
<target name="start" description="starts jboss instance">
    <antcall target="start-jboss">
        <param name="jboss.home" value="${my.jboss.home}" />
        <param name="jboss.name" value="${my.jboss.name}" />
    </antcall>
</target>

<target name="debug" description="starts jboss instance in debugmode">
    <antcall target="start-jboss-debug">
        <param name="jboss.home" value="${my.jboss.home}" />
        <param name="jboss.name" value="${my.jboss.name}" />
        <param name="jboss.debugport" value="${my.jboss.debugport}" />
    </antcall>
</target>

<target name="stop" description="stops jboss instance">
    <antcall target="exec-jboss">
        <param name="jboss.home" value="${my.jboss.home}" />
        <param name="jboss.host" value="${my.jboss.host}" />
        <param name="jboss.port" value="${my.jboss.port}" />
        <param name="jboss.command" value="shutdown" />
    </antcall>
</target>

<!-- a dependent build / package task should be present -->
<target name="deploy" description="deploys to a running jboss instance">
    <antcall target="exec-jboss">
        <param name="jboss.home" value="${my.jboss.home}" />
        <param name="jboss.host" value="${my.jboss.host}" />
        <param name="jboss.port" value="${my.jboss.port}" />
        <param name="jboss.command" value="deploy ${my.deployment}" />
    </antcall>
</target>