Tag Archives: SCP

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:

Apache Ant – Using scp and sshexec tasks in build.xml

Unlike the Ant Contrib library which could be included thru the <taskdef>, the <scp> and <sshexec> tasks could not be included in this way or it will throw the following errors.

  • A class needed by class org.apache.tools.ant.taskdefs.optional.ssh.Scp
    cannot be found: com/jcraft/jsch/…

 

If you want to make use of the SCP protocol to do file transfer in Apache Ant, first, visit JCraft and download the jsch-0.1.50.jar.

There are 2 ways to enable the <scp> and <sshexec> tasks in the Ant build.xml.
Continue reading Apache Ant – Using scp and sshexec tasks in build.xml