Some time ago I already explained how you could use Maven and the jboss-plugin to deploy your war or ear to your JBoss server. Now this works fine as long as your JBoss is a local installation running on the same machine as the one that is running Maven.
Of course there is a big chance that this is not the case in your development environment. In that case you can do the following in Maven to deploy your ear to the JBoss instance:

  1. Transfer the war or ear file to the remote machine
  2. Run a script on the remote machine

Actually it isn't doing anything JBoss specific, so you could use it for other application servers too (like Tomcat, at least when they are using hot deployment).
To perform step 1 you have to add the following plugin in your 'pom.xml':

XML:
  1. <build>
  2.   <plugins>
  3.     <plugin>
  4.       <groupId>org.codehaus.mojo</groupId>
  5.       <artifactId>wagon-maven-plugin</artifactId>
  6.       <version>1.0-beta-1</version>
  7.       <executions>
  8.         <execution>
  9.           <id>upload-artifact</id>
  10.           <phase>deploy</phase>
  11.           <goals>
  12.             <goal>upload</goal>
  13.           </goals>
  14.           <configuration>
  15.             <serverId>${project.deploy.serverId}</serverId>
  16.             <fromDir>target</fromDir>
  17.             <includes>*.war</includes>
  18.             <url>${project.deploy.url}</url>
  19.             <toDir>${project.deploy.toDir}</toDir>
  20.           </configuration>
  21.         </execution>
  22.       </executions>
  23.    </plugin>
  24.     ...
  25.   </plugin>
  26. </build>

And this plugin needs the 'distributionManagement' section to be filled like this:

XML:
  1. <distributionManagement>
  2.    <repository>
  3.      <id>m2-internal-repo</id>
  4.      <url>http://local.redstream.nl:8888/artifactory/libs-releases-local/</url>
  5.    </repository>
  6.    <snapshotRepository>
  7.      <id>m2-internal-repo</id>
  8.      <url>http://local.redstream.nl:8888/artifactory/libs-snapshots-local</url>
  9.    </snapshotRepository>
  10. </distributionManagement>

The second step is a bit more complicated. I want to execute a script on the remote server using SSH. This can rather easily be done by using an Ant target, so to get this working in Maven we have to use the plugin to run an Ant target. It will ook like this:

XML:
  1. <plugin>
  2.      <groupId>org.apache.maven.plugins</groupId>
  3.      <artifactId>maven-antrun-plugin</artifactId>
  4.      <version>1.3</version>
  5.      <dependencies>
  6.        <dependency>
  7.          <groupId>org.apache.ant</groupId>
  8.          <artifactId>ant-jsch</artifactId>
  9.          <version>1.7.1</version>
  10.        </dependency>
  11.        <dependency>
  12.          <groupId>com.jcraft</groupId>
  13.          <artifactId>jsch</artifactId>
  14.          <version>0.1.41</version>
  15.        </dependency>
  16.        </dependencies>
  17.          <executions>
  18.            <execution>
  19.              <id>deploy-artifact</id>
  20.              <phase>deploy</phase>
  21.              <goals>
  22.                <goal>run</goal>
  23.              </goals>
  24.              <configuration>
  25.                <tasks>
  26.                   <sshexec host="${project.deploy.host}"
  27.                                   username="${projecte.deploy.username}"
  28.                                   password="${project.deploy.password}"
  29.                                   trust="true"
  30.                                  command="bin/deploy_web.sh"/>
  31.                </tasks>
  32.              </configuration>
  33.            </execution>
  34.          </executions>
  35.       </plugin>

Thta's it. These two plugins together do the job. For completeness I show the used properties that I have setup in my 'settings.xml':

XML:
  1. <profiles>
  2.   <profile>
  3.     <id>develop</id>
  4.     <properties>
  5.       <project.deploy.serverId>mule-server</mule.deploy.serverId>
  6.       <project.deploy.url>scp://mule-server</mule.deploy.url>
  7.       <project.deploy.toDir>/home/pascal</mule.deploy.toDir>
  8.       <project.deploy.host>mule-server</mule.deploy.host>
  9.       <project.deploy.username>pascal</mule.deploy.username>
  10.       <project.deploy.password>pascal</mule.deploy.password>
  11.     </properties>
  12.   </profile>
  13.   ...
  14. </profiles>

And the script that is executed at the remote server 'deploy_web.sh':

CODE:
  1. #
  2. # Deploy Mule applications
  3. #
  4. #
  5. source /etc/profile
  6.  
  7. echo "Start deploying"
  8.  
  9. for archive in ~/deploy/*.war; do
  10.   echo "Copying to tomcat: web-archive \"$archive\""
  11.   cp $archive /$TOMCAT_HOME/webapps/
  12. done
  13. echo "Deploying finished"
  14. echo "Clean up ~/deploy directory"
  15. rm -rf ~/deploy/*.war

If all this is in place you can deploy the ear/war file by using the command:
mvn clean deploy
Like I said before there is nothing JBoss specific to this and actually I am using the script to deploy my Mule applications to our Tomcat server.