我正在尝试将maven构建的jar复制到远程主机中的目录,而不是存储库。我在这里尝试了user1050755的答案Using Maven for deployment,它使用了maven-antrun-plugin,而且我也试过了wagon-ssh插件。以下是我的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>
对于这两个插件,我都会遇到同样的错误
[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]
但我不想部署到存储库,我认为antrun-plugin会让我将文件复制到远程主机而没有任何限制,我缺少什么?
答案 0 :(得分:1)
因为您使用阶段部署,所以您需要distributionManagement或altDeploymentRepository: 在您的情况下,有两种解决方案:
像这样跳过部署阶段:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>X.Y</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
更改
<phase>deploy</phase>
要
<phase>install</phase>
答案 1 :(得分:1)
我最终使用了maven-antrun-plugin但是使用了集成测试。我使用的maven命令是mvn package integration-test
。我还使用了trust =&#34; true&#34;属性,因为我无法摆脱jsch异常com.jcraft.jsch.JSchException: UnknownHostKey:
。我在这里发布了一个关于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>
答案 2 :(得分:0)
你解决了这个问题吗?
我在使用Apache Maven 3.2.5的Windows平台上遇到了同样的问题
原因是maven无法检测到&lt; server&gt;在settings.xml配置
所以我的解决方案如下。
<configuration> <url>scp://root@192.168.56.102</url> </configuration>
然后在命令行输入密码。
现在,我试图找出更好的解决方案。
我希望如此......