我有一个支持primefaces的JSF项目。我想使用ant脚本进行complie和部署操作。我创建了以下build.xml。这个Ant脚本正在编译和部署项目到jboss 7.1。但我无法为jboss停止和重启操作创建ant目标。我用Google搜索并在此链接中找到了旧jboss版本的ant任务:
How to start and stop jboss server using Ant task?
但是Jboss 7.1不再有“shutdown.bat”和“restart.bat”了。
有没有人有这个问题的经验?
感谢。
在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>
答案 0 :(得分:8)
尝试使用jboss-cli.bat。
> bin\jboss-cli.bat --connect --command=:shutdown
如果--connect
不是localhost,则需要添加target ip作为参数。
重启(实际重装)
> bin\jboss-cli.bat --connect --command=:reload
来自GreenGiant的评论,完全重启:
> bin\jboss-cli.bat --connect --command=:shutdown(restart=true)
答案 1 :(得分:2)
感谢。 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>
答案 2 :(得分:0)
如上所述:
How to start and stop jboss server using Ant task?
适当的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>