Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven部署到远程主机ssh(scp)而不是存储库_Maven_Ssh_Scp_Maven Antrun Plugin_Maven Wagon Plugin - Fatal编程技术网

Maven部署到远程主机ssh(scp)而不是存储库

Maven部署到远程主机ssh(scp)而不是存储库,maven,ssh,scp,maven-antrun-plugin,maven-wagon-plugin,Maven,Ssh,Scp,Maven Antrun Plugin,Maven Wagon Plugin,我试图将maven构建的jar复制到远程主机中的目录,而不是存储库中。我在这里尝试了user1050755 answer,它使用了maven antrun插件,还尝试了Vang ssh插件。下面是我的pom.xml的相关摘录 <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId&

我试图将maven构建的jar复制到远程主机中的目录,而不是存储库中。我在这里尝试了user1050755 answer,它使用了maven antrun插件,还尝试了Vang 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>

但我不想部署到存储库,我认为antrun插件只会让我无限制地将文件复制到远程主机,我缺少什么?

因为您使用phase deploy,所以需要distributionManagement或altDeploymentRepository: 在您的案例中,有两种解决方案:

  • 跳过部署阶段,如下所示:

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-deploy-plugin</artifactId>
       <version>X.Y</version>
       <configuration>
          <skip>true</skip>
       </configuration>
    </plugin>
    
    
    org.apache.maven.plugins
    maven部署插件
    X.Y
    真的
    
  • 改变

    <phase>deploy</phase>
    
    部署
    
  • 安装
    
    您解决了这个问题吗

    我在使用ApacheMaven3.2.5的windows平台上遇到了同样的问题

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

    下面是我的解决方案

  • 将ssh帐户添加到url
  • scp://root@192.168.56.102
  • mvn部署
  • 然后在命令行输入密码

    现在,我想找出一个更好的解决办法


    我希望如此…

    我最终使用了maven antrun插件,但在该阶段使用了集成测试。我使用的maven命令是mvn包集成测试。我还使用了trust=“true”属性,因为我无法摆脱jsch异常
    com.jcraft.jsch.JSchException:UnknownHostKey:
    。我在这里贴了一个问题

    
    maven antrun插件
    1.8
    scp
    集成测试
    跑
    com.jcraft
    jsch
    0.1.53
    org.apache.ant
    ant jsch
    1.9.6
    
    <phase>deploy</phase>
    
        <phase>install</phase> 
    
    <configuration> <url>scp://root@192.168.56.102</url> </configuration>
    <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>