简体   繁体   English

如何使用Ant脚本停止并重新启动JBoss 7.1 Application Server?

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

I have a JSF project that supported with primefaces. 我有一个支持primefaces的JSF项目。 I want to use ant script for complie and deployment operations. 我想使用ant脚本进行complie和部署操作。 I created following build.xml. 我创建了以下build.xml。 This Ant script is compiling and deploying project to jboss 7.1. 这个Ant脚本正在编译和部署项目到jboss 7.1。 But I could not create ant target for jboss stop and restart operation. 但我无法为jboss停止和重启操作创建ant目标。 I googled and found a ant task for old jboss version int this link: 我用Google搜索并在此链接中找到了旧jboss版本的ant任务:

How to start and stop jboss server using Ant task? 如何使用Ant任务启动和停止jboss服务器?

but Jboss 7.1 does not have "shutdown.bat" and "restart.bat" anymore. 但是Jboss 7.1不再有“shutdown.bat”和“restart.bat”了。

Is there anyone who have experiences with this problem? 有没有人有这个问题的经验?

Thanks. 谢谢。

Build.xml: 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. 尝试使用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. 如果不是localhost,则需要添加target ip作为--connect参数。

For restart (actually reload) 重启(实际重装)

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

From comment by GreenGiant, for a full restart: 来自GreenGiant的评论,完全重启:

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

Thanks. 谢谢。 Ant Script target should be like this: Ant Script目标应该是这样的:

<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? 如何使用Ant任务启动和停止jboss服务器?

The appropriate os independent answer would be something like this: 适当的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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