Mario
Mario

Reputation: 21

JBoss remote deploy using ANT script

Is it possible to do remote deploy of application (jar file) on JBoss using ANT script?

I found only few suggestions to do copy, but that can be done only on local server.

Upvotes: 2

Views: 2592

Answers (2)

mwelt
mwelt

Reputation: 11

To deploy remote you can use the jboss-cli, which is included in jboss. To make this approach work you have to have a local jboss install, because it includes the jboss-cli jar. Then you will need a jboss-user on the remote host, which you can create with the add-user.(sh|bat) on the remote box. Then you can use the following ant-tasks to deploy:

<!-- local installation to find the correct jar -->
<property name="local.jboss.home" value="/path/to/jboss/install/dir" />

<!-- remote parts -->
<property name="remote.jboss.host" value="some.ip" />
<property name="remote.jboss.port" value="9999" />

<property name="remote.jboss.user" value="user" />
<property name="remote.jboss.password" value="password" />


<!-- supposedly this is built by a seperate task -->
<property name="my.deployment" value="${basedir}/build/foo.war" />

<!-- 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="--user=${jboss.user}" />
        <arg value="--password=${jboss.password}" />
        <arg value="--connect" />
    </java>
</presetdef>

<!-- the exec some command on cli command -->
<target name="exec-jboss">
    <jboss-cli failonerror="true">
        <arg value="${jboss.command}" />
    </jboss-cli>
</target>

<target name="deploy" description="deploys to a running jboss instance">
    <antcall target="exec-jboss">
        <param name="jboss.home" value="${local.jboss.home}" />
        <param name="jboss.host" value="${remote.jboss.host}" />
        <param name="jboss.port" value="${remote.jboss.port}" />
        <param name="jboss.command" value="deploy ${my.deployment}" />
    </antcall>
</target>

Upvotes: 1

Liping Huang
Liping Huang

Reputation: 4476

Mainly there are two approaches to do remote JBOSS deploy.

  • Cargo This tool providing the ant scripts to do the remote deploy/control JBOSS instance
  • Copy approach. The main steps are copy the application files to the jboss deploy folder and then start the jboss by remote command.
    For example, you can use SCP task to copy the application file to remote host, and then use the SSHEXEC task to remove control the JBOSS_BIN/ shell to start/stop jboss instance.

Upvotes: 1

Related Questions