How to start and stop jboss server using Ant task?

前端 未结 3 1112
挽巷
挽巷 2021-01-19 01:35

I need to stop, deploy my ear file and start Jboss server using the Ant tasks.

I am able to compile, build and deploy my J2EE application as an ear file into the JBo

相关标签:
3条回答
  • 2021-01-19 02:15

    Cargo supports ANT and is designed to support several J2EE containers

    0 讨论(0)
  • 2021-01-19 02:35

    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>
    
    0 讨论(0)
  • 2021-01-19 02:36

    Here how you start/stop JBoss app container including deploy an application :

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

    Hope this is helpful :)

    0 讨论(0)
提交回复
热议问题