3

我有一个支持 primefaces 的 JSF 项目。我想使用 ant 脚本进行编译和部署操作。我创建了以下 build.xml。这个 Ant 脚本正在编译和部署项目到 jboss 7.1。但我无法为 jboss 停止和重新启动操作创建 ant 目标。我用谷歌搜索并在此链接中找到了旧 jboss 版本的 ant 任务:

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

但是 Jboss 7.1 不再有“shutdown.bat”和“restart.bat”了。

有没有人有这个问题的经验?

谢谢。

构建.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>

4

3 回答 3

10

尝试使用 jboss-cli.bat。

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

--connect如果不是 localhost,则需要添加目标 ip 作为参数。

重新启动(实际上是重新加载)

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

来自 GreenGiant 的评论,完全重启:

> bin\jboss-cli.bat --connect --command=:shutdown(restart=true)
于 2013-09-13T14:44:50.023 回答
2

谢谢。Ant 脚本目标应该是这样的:

<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>
于 2013-09-13T19:16:48.913 回答
0

如此处所述:

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

适当的操作系统独立答案将是这样的:

<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>
于 2015-11-18T10:39:32.553 回答