Maven 部署到远程主机 ssh(scp) 而不是存储库
Maven deploy to remote host ssh(scp) not repository
我正在尝试将 maven 构建的 jar 复制到远程主机中的目录,而不是存储库。我在这里 Using Maven for deployment 尝试了 user1050755 的回答,它使用了 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 只会让我无限制地将文件复制到远程主机,我错过了什么?
因为您使用阶段部署,所以您需要 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>
你解决这个问题了吗?
我在使用 Apache Maven 3.2.5
的 windows 平台上遇到了同样的问题
原因是 maven 无法在 settings.xml
检测到 配置
所以我的解决方案如下。
- 将 ssh 帐户添加到 url。
<configuration>
<url>scp://root@192.168.56.102</url>
</configuration>
- mvn 部署
然后在命令行输入密码。
现在,我想找出更好的解决方案。
希望如此...
我最终使用了 maven-antrun-plugin,但在该阶段使用了集成测试。我使用的 maven 命令是 mvn package integration-test
。我还使用了 trust="true" 属性,因为我无法摆脱 jsch 异常 com.jcraft.jsch.JSchException: UnknownHostKey:
。我在这里发布了一个问题
<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>
我正在尝试将 maven 构建的 jar 复制到远程主机中的目录,而不是存储库。我在这里 Using Maven for deployment 尝试了 user1050755 的回答,它使用了 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 只会让我无限制地将文件复制到远程主机,我错过了什么?
因为您使用阶段部署,所以您需要 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>
你解决这个问题了吗?
我在使用 Apache Maven 3.2.5
的 windows 平台上遇到了同样的问题原因是 maven 无法在 settings.xml
检测到所以我的解决方案如下。
- 将 ssh 帐户添加到 url。
<configuration> <url>scp://root@192.168.56.102</url> </configuration>
- mvn 部署
然后在命令行输入密码。
现在,我想找出更好的解决方案。
希望如此...
我最终使用了 maven-antrun-plugin,但在该阶段使用了集成测试。我使用的 maven 命令是 mvn package integration-test
。我还使用了 trust="true" 属性,因为我无法摆脱 jsch 异常 com.jcraft.jsch.JSchException: UnknownHostKey:
。我在这里发布了一个问题
<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>