Maven – Run sshexec and scp in maven-antrun-plugin

If you want to use the <sshexec> or <scp> tasks in the maven-antrun-plugin, you may find the following error.

  • [ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (default-cli) on project fraudcheck: An Ant BuildException has occured…

 

Just like what we have discussed in Apache Ant – Using scp and sshexec tasks in build.xml, you need to define the <sshexec> or <scp> tasks in the Ant script. Try to configure your pom.xml as follow.

...
<!-- Deployment using Ant -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.7</version>
  <dependencies>
    <!-- Include Ant-Contrib tasks -->
    <dependency>
      <groupId>ant-contrib</groupId>
      <artifactId>ant-contrib</artifactId>
      <version>20020829</version>
    </dependency>
    <!-- Include sshexec task -->
    <dependency>
      <groupId>org.apache.ant</groupId>
      <artifactId>ant-jsch</artifactId>
      <version>1.9.2</version>
    </dependency>
    <dependency>
      <groupId>com.jcraft</groupId>
      <artifactId>jsch</artifactId>
      <version>0.1.50</version>
    </dependency>
  </dependencies>
  <configuration>
    <tasks>
      <!-- Add the sshexec and scp task -->
      <taskdef name="sshexec"
        classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
        classpathref="maven.plugin.classpath" />
      <taskdef name="scp"
        classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp"
        classpathref="maven.plugin.classpath" />

      <!-- Rest of the Ant script -->
    </tasks>
  </configuration>
  <goals>
    <goal>run</goal>
  </goals>
</plugin>
...

 

Done =)

Reference:

  • Jukka Palomäki – Automated WAR deployment
  • StackOverflow – Run remote command via ssh using Maven3
  • Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s