2016-12-21 37 views
0

我在maven中有一些模塊,並且我想構建一個模塊的jar,它具有其他模塊的依賴關係。如何從一個maven模塊與其他模塊的依賴關係構建一個jar?

如何在jar中包含兩個模塊?

編輯:

我有以下模塊:

myproject-core/ 
    myproject-api/ 
    myproject-dependencie/ 
    myproject-api-web/ 

而且我要打造的myproject-API與myproject的-dependencie一個罐子。我在myproject-api中有更多的依賴關係,我只需要在這個jar中myproject-api和myproject-dependencie。

謝謝!

+0

你不清楚你想在這裏做什麼,你能澄清你有什麼,你想要什麼?你可以發佈一些樣本POM來幫助嗎? – Tunaki

+0

我編輯了更多的細節,謝謝 –

回答

1

我猜Maven的遮陽簾插件將是您的朋友:

https://maven.apache.org/plugins/maven-shade-plugin/

在你的插件部分是這樣的:

...

<properties> 
     <shade-main-class>{your-main-class}</shade-main-class> 
    </properties> 

...

...

  <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>2.4.3</version> 
       <configuration> 
        <createDependencyReducedPom>false</createDependencyReducedPom> 
        <filters> 
         <filter> 
          <artifact>*:*</artifact> 
      <includes> 
       <include>com/yourcompany/**</include> 
       </includes> 
          <excludes> 
           <exclude>META-INF/*.SF</exclude> 
           <exclude>META-INF/*.DSA</exclude> 
           <exclude>META-INF/*.RSA</exclude> 
          </excludes> 
         </filter> 
        </filters> 
       </configuration> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <transformers> 
           <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> 
           <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
            <mainClass>${shade-main-class}</mainClass> 
           </transformer> 
          </transformers> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
... 
+0

嗨thelINtoy,與此代碼,我想我會得到一個jar與所有依賴項,但我不想所有的依賴關係,我只是想要其中之一。 –

+0

我想我可以使用排除標籤來排除其餘的依賴關係...但是我已經很安靜了很多,我正在尋找其他方式... –

+0

編輯完問題後,我已經更新了答案,以顯示您可以使用包括過濾器 – theINtoy

相關問題