2016-09-26 90 views
0

我有maven項目。當我點擊安裝 maven build zipjar文件在target文件夾中。maven添加zip文件部署到遠程服務器

但是當我點擊部署它只部署JAR文件和依賴於遠程倉庫。

問題:我如何使用標準maven插件添加zip文件以部署到遠程nexus存儲庫。

編輯

<packaging>custom-zip<packaging>

+0

'.zip'文件是'target'文件夾內容的一部分,但它被複制到本地'm2'緩存中嗎?我認爲不是,只有'.jar'應該在那裏,然後與'deploy'行爲一致。你能分享更多有關'pom.xml'文件嗎?大多數情況下,'zip'文件是通過不附加到構建作爲附加的神器生成的 –

+0

@ A_Di-Matteo是的,你是對的。本地'm2 cache'中只有'.jar'。 我只是有一個特殊的插件'定製插件包裝郵編' 而這個插件爲我''zip'文件在'target'文件夾。 我該如何附加這個來構建額外的神器? –

回答

2

爲了正確installdeploy額外的神器(由編譯生成的文件,通常也是繼其版本和有關項目成果的連貫部分),你需要附加它的構建,以便Maven將其作爲其結果的正式交付處理。

要將文件附加到構建,可以使用build-helper-maven-plugin

下面是它的usage頁的樣本代碼片段:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <version>1.12</version> 
    <executions> 
     <execution> 
     <id>attach-artifacts</id> 
     <phase>package</phase> 
     <goals> 
      <goal>attach-artifact</goal> 
     </goals> 
     <configuration> 
      <artifacts> 
      <artifact> 
       <file>the-generated-file</file> 
       <type>extension of your file</type> 
       <classifier>optional</classifier> 
      </artifact> 
      </artifacts> 
     </configuration> 
     </execution> 
    </executions> 
</plugin> 

您應該將上述負責文件的生成插件之後的聲明配置,即,該文件應該存在你的時候嘗試將其附加到構建。查看file配置元素,在這裏您應該指定文件,例如target\myfile.zip。在這種情況下,它將在package階段附加,以便installdeploy階段在處理期間將其考慮在內。

調用當

mvn clean install 

然後你會看到作爲構建輸出的一部分:

[INFO] --- build-helper-maven-plugin:1.12:attach-artifact (attach-artifacts) @ zip-example --- 
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ zip-example --- 
[INFO] Installing C:\data\eclipse-workspace\zip-example\target\zip-example-0.0.1-SNAPSHOT.jar to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT.jar 
[INFO] Installing C:\data\eclipse-workspace\zip-example\pom.xml to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT.pom 
[INFO] Installing C:\data\eclipse-workspace\zip-example\sample.zip to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT-optional.zip 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 

注:sample.zip實際上是複製到m2的本地庫zip-example-0.0.1-SNAPSHOT-optional.zip,因此根據改名項目配置(artifactId,version,classifier)。

+0

@ArturGaniev你是否嘗試過這種方法? –

+0

對不起,延遲迴答。 非常感謝 - 它的工作原理。 ! –

相關問題