简体   繁体   中英

How to Stop and Restart JBoss 7.1 Application Server With Ant script?

I have a JSF project that supported with primefaces. I want to use ant script for complie and deployment operations. I created following build.xml. This Ant script is compiling and deploying project to jboss 7.1. But I could not create ant target for jboss stop and restart operation. I googled and found a ant task for old jboss version int this link:

How to start and stop jboss server using Ant task?

but Jboss 7.1 does not have "shutdown.bat" and "restart.bat" anymore.

Is there anyone who have experiences with this problem?

Thanks.

Build.xml:

<project default="run" basedir="." name="portal">
<property environment="env"/>
<property name="JBOSS_HOME" value="C:/jboss-as-7.1.1.Final"/>
<property name="JBoos.deployment.dir" value="${JBOSS_HOME}/standalone/deployments"/>
<property name="JBoos.bin" value="${JBOSS_HOME}/bin"/>
<property name="base" value="."/>
<property name="source" value="${base}/src"/>

<target name="run" depends="clean, compile">
    <war warfile="portal.war" needxmlfile = "false" >
        <fileset dir="${source}/main/webapp"/>
        <classes dir="D:/portalAnt/WEB-INF/classes"/>
        <lib file = "C:/MavenRepo/.m2/repository/org/primefaces/primefaces/3.5/primefaces-3.5.jar"/>
        <metainf dir="D:/Personel/Dropbox/Java/primeFaces_WS/portal/target/m2e-wtp/web-resources/META-INF"/>
    </war>
        <antcall target="deployTarget"/>
        <antcall target="startJboss"/>
</target>

<target name="deployTarget">
    <copy file="${base}/portal.war" todir="${JBoos.deployment.dir}"/>
</target>

<target name="startJboss">
    <exec executable="${JBoos.bin}/standalone.bat"/>
</target>

<target name="stopJboss">

</target>   

<path id="MavenLib">
     <!-- Maven libs are here. -->
</path>

<path id="JbossLib">
   <!-- Jboss libs are here. -->
</path>

<path id="portal.classpath">
    <path refid="MavenLib"/>
    <path refid="JBossLib"/>
</path>

<target name="compile">
    <javac includeantruntime="false" srcdir="./src" destdir="D:/portalAnt/WEB-INF/classes">
        <classpath refid="portal.classpath"/>
    </javac>
    <mkdir dir="D:/portalAnt/WEB-INF/classes/META-INF"/>
    <copy file="${base}/src/main/resources/META-INF/persistence.xml" todir="D:/portalAnt/WEB-INF/classes/META-INF"/> 
</target>

<target name="clean">
    <delete file ="${JBoos.deployment.dir}/portal.war"/>
</target>

Try using jboss-cli.bat.

> bin\jboss-cli.bat --connect --command=:shutdown

You need to add target ip as parameter for --connect , if it is not localhost.

For restart (actually reload)

> bin\jboss-cli.bat --connect --command=:reload

From comment by GreenGiant, for a full restart:

> bin\jboss-cli.bat --connect --command=:shutdown(restart=true)

Thanks. Ant Script target should be like this:

<target name="stopJboss">
    <exec executable="${JBoos.bin}/jboss-cli.bat">
        <arg value="--connect" />
        <arg value="--command=:shutdown" />
    </exec>
</target>

<target name="reloadJboss">
    <exec executable="${JBoos.bin}/jboss-cli.bat">
        <arg value="--connect" />
        <arg value="--command=:reload" />
    </exec>
</target>

As mentioned here:

How to start and stop jboss server using Ant task?

The appropriate os independent answer would be something like this:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM