2016-12-21 41 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

相关问题