2016-07-16 94 views
0

我正在嘗試將我的Maven Java項目部署到我創建的內部存儲庫。Maven通過SFTP部署不起作用

我使用Ubuntu我的dev的機器,我可以用下面的命令連接到回購:

ftp -P7123 [email protected]_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> 

當我運行部署目標時,我g et以下錯誤:

[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: [email protected]] 
[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 [email protected]:/public/settings.xml settings.xml 

會爲我的回購會由於安全設置。

我看不到在命令中我可以告訴它使用sftp而不是ssh或scp。

+0

你爲什麼用這種極端的舊版本旅行車? Wagon的當前版本是2.10 http://maven.apache.org/wagon/此外,爲什麼不使用像Nexus這樣的現有版本庫管理器? – khmarbaise

+0

我從http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ssh-external.html複製了我的擴展。我將嘗試使用2.1並找到一個示例,並複製 – Robert3452

+0

我已使用Google搜索nexus並提出了http://www.sonatype.com/download-oss-sonatype我的網站服務器是一個廉價的在線網站,只有512mb的ram,並且已經有一噸的東西了。現在我不想只使用基於文件的簡單回購。 Nexus是我將來要研究的內容。 – Robert3452

回答

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> 

工作的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>