【问题标题】:Maven deploy to remote host ssh(scp) not repositoryMaven 部署到远程主机 ssh(scp) 而不是存储库
【发布时间】:2015-11-17 04:23:35
【问题描述】:

我正在尝试将 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 只会让我将文件复制到没有限制的远程主机,我错过了什么?

【问题讨论】:

    标签: maven ssh scp maven-antrun-plugin maven-wagon-plugin


    【解决方案1】:

    我最终使用了 maven-antrun-plugin,但在该阶段使用了集成测试。我使用的 maven 命令是mvn package integration-test。我还使用了 trust="true" 属性,因为我无法摆脱 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】:

      因为你使用阶段部署,你需要distributionManagement或altDeploymentRepository: 在您的情况下,有两种解决方案:

      1. 像这样跳过部署阶段:

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

        <phase>deploy</phase>
        

          <phase>install</phase> 
      

      【讨论】:

        【解决方案3】:

        这个问题你解决了吗?

        我在 Windows 平台上使用 Apache Maven 3.2.5 遇到了同样的问题

        原因是maven无法在settings.xml中检测到配置

        所以我的解决方案如下。

        1. 将 ssh 帐户添加到 url。
        scp://root@192.168.56.102配置>
        1. mvn 部署

        然后在命令行输入密码。

        现在,我正在尝试找出更好的解决方案。

        希望如此……

        【讨论】:

          猜你喜欢
          • 2014-02-15
          • 2020-06-24
          • 2023-03-03
          • 1970-01-01
          • 1970-01-01
          • 2012-11-23
          • 1970-01-01
          • 2023-03-09
          • 1970-01-01
          相关资源
          最近更新 更多