2016-08-25 26 views
2

我想使用maven-assembly-plugin將外部依賴關係打包到應用程序的jar文件中。當我調用mvn安裝時,它會創建兩個jar文件,一個是沒有依賴關係的文件。 (appname-version.jar和appname-version-jar -with-dependencies.jar)Maven assembly plugin創建兩個意外的jar

我的問題是爲什麼它會創建兩個jar文件?

這裏是插件:(不使用IM任何其他插件的那一刻)

<plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <configuration> 
      <archive> 
       <manifest> 
        <mainClass>com.coolapp.mainClass</mainClass> 
       </manifest> 
      </archive> 
      <descriptorRefs> 
       <descriptorRef>jar-with-dependencies</descriptorRef> 
      </descriptorRefs> 
     </configuration> 
     <executions> 
      <execution> 
       <id>make-assembly</id> <!-- this is used for inheritance merges --> 
       <phase>package</phase> <!-- bind to the packaging phase --> 
       <goals> 
        <goal>single</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 

謝謝!

+0

更新了我的答案 – alexbt

回答

2

您需要定義maven-jar-plugin以避免創建默認jar。這是通過添加<phase>none</phase>其執行細節進行:

<plugin> 
    <artifactId>maven-jar-plugin</artifactId> 
    <version>3.0.2</version> 
    <executions> 
     <execution> 
     <id>default-jar</id> 
     <phase>none</phase> 
     </execution> 
    </executions> 
</plugin> 

所有資源/類依然會被移動到目標文件夾,所以Maven的組件能夠正確地構建自身。

+0

它像一個魅力。謝謝! – Nandor

相關問題