通过SFTP进行Maven部署无法正常工作

时间:2016-07-16 09:40:06

标签: java eclipse maven

我正在尝试将我的maven Java项目部署到我创建的内部存储库。

我在我的开发机器上使用Ubuntu,我可以使用以下命令连接到Repo:

ftp -P7123 maven_repo@my_domain.com

这给了我一个有效的联系。我使用非标准端口和公钥以用户maven_repo登录。

我的项目是eclipse,我正在使用m2e内置的eclipse来运行maven。

我将这些部分添加到我的pom.xml文件中:

  <distributionManagement>
    <repository>
      <id>ssh-repository</id>
      <url>scpexe://mvn.metcarob.com:7456/public</url>
    </repository>
  </distributionManagement>

<extensions>
  <!-- Enabling the use of SSH -->
  <extension>
    <groupId>org.apache.maven.wagon</groupId>
     <artifactId>wagon-ssh-external</artifactId>
     <version>1.0-beta-6</version>
  </extension>
</extensions>  

我的安装没有〜/ .m2 / settings.xml,我已经读过它默认不存在,我需要创建它所以我创建它:(基于在线示例)

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
      <localRepository/>
      <interactiveMode/>
      <usePluginRegistry/>
      <offline/>
      <pluginGroups/>
      <servers>
          <server>
              <id>ssh-repository</id>
              <username>maven_repo</username>
              <privateKey>/home/robert/.ssh/id_rsa</privateKey>
          </server>
      </servers>
      <mirrors/>
      <proxies/>
      <profiles/>
      <activeProfiles/>
    </settings>

当我运行部署目标时,我收到以下错误:

[DEBUG] Configuring mojo org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-deploy-plugin:2.7, parent: sun.misc.Launcher$AppClassLoader@5c647e05]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy' with basic configurator -->
[DEBUG]   (f) artifact = metcarob.com.BobDiary:BobDiary:jar:0.0.1-SNAPSHOT
[DEBUG]   (f) attachedArtifacts = [metcarob.com.BobDiary:BobDiary:jar:jar-with-dependencies:0.0.1-SNAPSHOT]
[DEBUG]   (s) localRepository =       id: local
      url: file:///home/robert/.m2/repository/
   layout: default
snapshots: [enabled => true, update => always]
 releases: [enabled => true, update => always]

[DEBUG]   (f) offline = false
[DEBUG]   (f) packaging = jar
[DEBUG]   (f) pomFile = /home/robert/eclipse/BobProjects/BobDiary/pom.xml
[DEBUG]   (f) project = MavenProject: metcarob.com.BobDiary:BobDiary:0.0.1-SNAPSHOT @ /home/robert/eclipse/BobProjects/BobDiary/pom.xml
[DEBUG]   (f) retryFailedDeploymentCount = 1
[DEBUG]   (f) skip = false
[DEBUG]   (f) updateReleaseInfo = false
[DEBUG] -- end configuration --
[WARNING] Error injecting: org.apache.maven.wagon.providers.ssh.external.ScpExternalWagon
java.lang.NoClassDefFoundError: org/codehaus/plexus/util/cli/CommandLineException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
    at java.lang.Class.getDeclaredConstructors(Class.java:2020)
    ... (More removed)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.956 s
[INFO] Finished at: 2016-07-16T10:35:28+01:00
[INFO] Final Memory: 14M/407M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project BobDiary: Execution default-deploy of goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy failed: A required class was missing while executing org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy: org/codehaus/plexus/util/cli/CommandLineException
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-deploy-plugin:2.7
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/robert/.m2/repository/org/apache/maven/plugins/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.jar
[ERROR] urls[1] = file:/home/robert/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
[ERROR] urls[2] = file:/home/robert/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>metcarob.com.BobDiary:BobDiary:0.0.1-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]
[ERROR] 
[ERROR] -----------------------------------------------------: org.codehaus.plexus.util.cli.CommandLineException
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project BobDiary: Execution default-deploy of goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy failed: A required class was missing while executing org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy: org/codehaus/plexus/util/cli/CommandLineException
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-deploy-plugin:2.7
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/home/robert/.m2/repository/org/apache/maven/plugins/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.jar
urls[1] = file:/home/robert/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
urls[2] = file:/home/robert/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[project>metcarob.com.BobDiary:BobDiary:0.0.1-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

-----------------------------------------------------

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)

任何人都可以帮我解决这个问题吗?

**更新1 我将POM文件中的扩展名更改为:

  <extension>
    <groupId>org.apache.maven.wagon</groupId>
     <artifactId>wagon-ssh-external</artifactId>
     <version>2.10</version>
  </extension>

我现在得到一个不同的错误:

INFO] Downloading: scpexe://mvn.metcarob.com:7456/public/metcarob/com/BobDiary/BobDiary/0.0.1-SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata metcarob.com.BobDiary:BobDiary:0.0.1-SNAPSHOT/maven-metadata.xml from/to ssh-repository (scpexe://mvn.metcarob.com:7456/public): Exit code: 1 - Host key verification failed.

org.eclipse.aether.transfer.MetadataTransferException: Could not transfer metadata metcarob.com.BobDiary:BobDiary:0.0.1-SNAPSHOT/maven-metadata.xml from/to ssh-repository (scpexe://mvn.metcarob.com:7456/public): Exit code: 1 - Host key verification failed.

    at org.eclipse.aether.connector.basic.MetadataTransportListener.transferFailed(MetadataTransportListener.java:43)
    at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355)

这是“主机密钥验证失败”。 我有几个问题: 我需要它使用sftp而不是scp,命令:

scp -P7456 maven_repo@metcarob.com:/public/settings.xml settings.xml
由于安全设置,

将因我的回购而失败。

我没有看到命令在哪里可以告诉它使用sftp而不是ssh或scp。

1 个答案:

答案 0 :(得分:0)

我找到了完整的答案。 我犯了两个错误。 1.Wagon-ssh-external的错误版本 2.主机密钥验证无效。

1是一个简单的修复,只是更改pom文件中的数字。 2有点复杂。在users~ / .ssh目录中有一个名为known_hosts的文件。我的开发机器上的主要用户有这个文件,但maven部署必须使用不同的文件,也许它在另一个用户下运行。我通过将它指向我的主要known_hosts文件来修复它,该文件中包含密钥。

工作文件部分是: pom.xml中:

  <distributionManagement>
    <repository>
      <id>ssh-repository</id>
            <name>ssh-repository</name>
      <url>scpexe://mvn.metcarob.com:7456/public</url>
    </repository>
  </distributionManagement>  

......构建部分......

<extensions>
  <!-- Enabling the use of SSH -->
  <extension>
    <groupId>org.apache.maven.wagon</groupId>
     <artifactId>wagon-ssh-external</artifactId>

     <version>2.10</version>
  </extension>
</extensions>  

working settings.xml:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
      <localRepository/>
      <interactiveMode/>
      <usePluginRegistry/>
      <offline/>
      <pluginGroups/>
      <servers>
          <server>
              <id>ssh-repository</id>
              <username>maven_repo</username>
              <configuration>
                  <sshExecutable>plink</sshExecutable>
                  <scpExecutable>sftp</scpExecutable>
                  <sshArgs></sshArgs>
                  <scpArgs>-o UserKnownHostsFile=/home/robert/.ssh/known_hosts</scpArgs>
              </configuration>
            <!-- <filePermissions>664</filePermissions>
            <directoryPermissions>775</directoryPermissions> -->
          </server>
      </servers>
      <mirrors/>
      <proxies/>
      <profiles/>
      <activeProfiles/>
</settings>