2017-05-04 109 views
1

我有三個apache-camel項目,可以說project-A,project-Bproject-C。項目-A具有依賴於項目B的Java主方法,項目B依賴於項目-C(在項目-B中添加了項目-C的依賴項,在項目A中添加了項目B依賴項)。我想爲項目B創建jar文件。我曾嘗試通過將項目A的pom.xml-從多個項目創建JAR文件,相互依賴

<plugins> 
    <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.4</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <artifactSet> 
          <excludes> 
           <exclude>org.jboss.seam:jboss-seam</exclude> 
          </excludes> 
         </artifactSet> 
         <transformers> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <manifestEntries> 
            <Main-Class>com.getusroi.featureinstaller.FeatureMetaInfoConfigInstaller</Main-Class> 
           </manifestEntries> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
           <resource>META-INF/spring.handlers</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
           <resource>META-INF/spring.schemas</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
           <resource>META-INF/services/org/apache/camel/TypeConverter</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> 

          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/maven/plugin.xml</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/spring.tooling</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/info.xml</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/DISCLAIMER</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/README.txt</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/DEPENDENCIES</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/LICENSE</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/LICENSE.txt</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/NOTICE</resource> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> 
           <resource>META-INF/NOTICE.txt</resource> 
          </transformer> 
         </transformers> 
         <filters> 
          filter out jar signatures from shaded jars 
          <filter> 
           <artifact>*:*</artifact> 
           <excludes> 
            <exclude>META-INF/*.SF</exclude> 
            <exclude>META-INF/*.DSA</exclude> 
            <exclude>META-INF/*.RSA</exclude> 
           </excludes> 
          </filter> 
         </filters> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <testSourceDirectory>src/test/java</testSourceDirectory> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
     </resource> 
    </resources> 
</plugins> 

問題裏面下面的配置我對着創建jar文件:項目B和項目-C裏面,我有兩個文件具有相同的名稱,所以在創建jar文件後,一個文件會被另一個文件覆蓋。任何幫助將非常感激。

回答

1

有一個父項目,建立所有3個在同一時間:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.greg</groupId> 
    <artifactId>example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <name>example</name> 

    <modules> 
    <module>project-a</module> 
    <module>project-b</module> 
    <module>project-c</module> 
    </modules> 

</project> 

的每個項目都可以具有本地項目依賴的需要,你的項目-B的pom.xml看起來像:

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
    <groupId>com.greg</groupId> 
    <artifactId>example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>project-b</artifactId> 

    <dependencies> 
    <dependency> 
     <groupId>com.greg</groupId> 
     <artifactId>project-c</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    </dependencies> 

<build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>3.0.0</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <transformers> 
           <transformer           implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
            <manifestEntries> 
             <Main-Class>com.greg.Application</Main-Class> 
            </manifestEntries> 
           </transformer> 
          </transformers> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 
    </build> 

</project> 

的executbale罐子將創建一個運行在項目-b的主要方法com.greg.Application /目標-1.0-SNAPSHOT.jar

+0

謝謝你的回答,' com.greg.App提示這是每個項目都需要的嗎?我在項目中只有一個主要方法-A – deen

+1

您只需要項目中的陰影插件來創建可執行的jar,其他項目就像依賴項,庫一樣。所以2個項目沒有插件,他們幫助建立1個生產罐子的項目。 –