1

I'm trying to copy a jar built by maven to a directory in a remote host, not a repository. I tried user1050755 answer here Using Maven for deployment which uses the maven-antrun-plugin and also I've tried the wagon-ssh plugin. Below is the hopefully relevant excerpt from my pom.xml

<build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>2.9</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>wagon-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <id>xd</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>upload</goal>
                        </goals>
                        <configuration>
                            <fromDir>target</fromDir>
                            <includes>xml-to-json-transformer-0.0.1-SNAPSHOT.jar</includes>
                                <excludes/>
                                <url>scp://spade.innoimm.local</url>
                                <toDir>/opt/xd/custom-modules/processor</toDir>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>scp</id>
                            <phase>deploy</phase>
                            <configuration>
                                <tasks>
                                    <scp todir="root@spade:/opt/xd/custom-modules/processor"
                                         sftp="true"
                                         keyfile="C:\MerucurioVagrant\repo\mercurio-vagrant\insecure_private_key.ppk"
                                         failonerror="false"
                                         verbose="true"
                                         passphrase="nopass"
                                    >
                                        <fileset dir="target">
                                            <include
                                                name="xml-to-json-transformer-0.0.1-SNAPSHOT.jar"/>
                                        </fileset>
                                    </scp>
                                </tasks>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.ant</groupId>
                            <artifactId>ant-jsch</artifactId>
                            <version>1.9.4</version>
                        </dependency>
                    </dependencies>
                </plugin>
        </plugins>
    </build>

For both plugins I get the same error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xml-to-json-transformer: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]

But I don't want to deploy to a repository, I thought the antrun-plugin would just let me copy a file to a remote host with no restrictions, what am I missing?

Community
  • 1
  • 1
gary69
  • 3,620
  • 6
  • 36
  • 50

3 Answers3

2

I ended up using the maven-antrun-plugin but used integration-test for the phase. The maven command I used was mvn package integration-test. I also used the trust="true" attribute because I couldn't get rid of a jsch exception com.jcraft.jsch.JSchException: UnknownHostKey:. I posted a question about that here JSch: UnknownHostKey exception even when the hostkey fingerprint is present in the known_hosts file

<plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <configuration>
                    <tasks>
                        <scp todir="vagrant@localhost:~/maven-scp"
                            port="2200" trust="true" keyfile="C:\keys\openSSH_pair1\open_ssh_private"
                            failonerror="false" verbose="true" passphrase="pass">
                            <fileset dir="target">
                                <include name="xml-to-json-transformer-0.0.1-SNAPSHOT.jar" />
                            </fileset>
                        </scp>
                    </tasks>
                </configuration>
                <executions>
                    <execution>
                        <id>scp</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.jcraft</groupId>
                        <artifactId>jsch</artifactId>
                        <version>0.1.53</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.ant</groupId>
                        <artifactId>ant-jsch</artifactId>
                        <version>1.9.6</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
Community
  • 1
  • 1
gary69
  • 3,620
  • 6
  • 36
  • 50
1

Because you use phase deploy ,you need distributionManagement or altDeploymentRepository: In your case , there are two solutions:

  1. skip deploy phase like this:

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-deploy-plugin</artifactId>
       <version>X.Y</version>
       <configuration>
          <skip>true</skip>
       </configuration>
    </plugin>
    
  2. Change

    <phase>deploy</phase>
    

To

    <phase>install</phase> 
Firouziam
  • 777
  • 1
  • 9
  • 31
question_maven_com
  • 2,457
  • 16
  • 21
0

Have you solved this problem?

I faced same issue at windows platform with Apache Maven 3.2.5

The reason is that maven can not detect <server> config at settings.xml

So My solution is below.

  1. add ssh account to url.

    <configuration>
        <url>scp://root@192.168.56.102</url>
    </configuration>

  1. mvn deploy

then typing password at command line.

Now, Im trying to figure out a better solution.

I hope so...

kris.jeong
  • 74
  • 3