2016-09-20 79 views
-1

我有一個maven項目,它應該產生幾個二進制文件。其中一些具有其他的依賴關係,並且依賴關係可能會從二進制到二進制不同。Maven項目中對多個二進制文件的不同依賴

問題是:如何在不包含每個依賴項的情況下實現這一目標,而只需將每個依賴項添加到每個jar中?

目前我使用程序集插件來完成工作,只是它將每個依賴項放入每個jar。此外,它創建了我不需要的標準app1快照jar。我怎樣才能擺脫它?

我的POM文件:

<?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>antlrtest</groupId> 
    <artifactId>app1</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>thf_test</id> 
         <phase>package</phase> <!-- bind to the packaging phase --> 
         <goals> 
          <goal>single</goal> 
         </goals> 
         <configuration> 
          <archive> 
           <manifest> 
            <mainClass>parsers.THF_test</mainClass> 
           </manifest> 
          </archive> 
          <descriptorRefs> 
           <descriptorRef>jar-with-dependencies</descriptorRef> 
          </descriptorRefs> 
          <finalName>bin/THF_test</finalName> 
         </configuration> 
        </execution> 
        <execution> 
         <id>hmf_test</id> 
         <phase>package</phase> <!-- bind to the packaging phase --> 
         <goals> 
          <goal>single</goal> 
         </goals> 
         <configuration> 
          <archive> 
           <manifest> 
            <mainClass>parsers.HMF_test</mainClass> 
           </manifest> 
          </archive> 
          <descriptorRefs> 
           <descriptorRef>jar-with-dependencies</descriptorRef> 
          </descriptorRefs> 
          <finalName>bin/HMF_test</finalName> 
         </configuration> 
        </execution> 
        <execution> 
         <id>HMF_to_THF</id> 
         <phase>package</phase> <!-- bind to the packaging phase --> 
         <goals> 
          <goal>single</goal> 
         </goals> 
         <configuration> 
          <archive> 
           <manifest> 
            <mainClass>transformation.HMF_to_THF</mainClass> 
           </manifest> 
          </archive> 
          <descriptorRefs> 
           <descriptorRef>jar-with-dependencies</descriptorRef> 
          </descriptorRefs> 
          <finalName>bin/HMF_to_THF</finalName> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <!-- antlr --> 
      <plugin> 
       <groupId>org.antlr</groupId> 
       <artifactId>antlr4-maven-plugin</artifactId> 
       <version>4.5</version> 
       <configuration> 
        <arguments> 
         <argument>-package</argument> 
         <argument>parsers</argument> 
        </arguments> 
       </configuration> 
       <executions> 
        <execution> 
         <id>antlr</id> 
         <goals> 
          <goal>antlr4</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>org.antlr</groupId> 
      <artifactId>antlr4-runtime</artifactId> 
      <version>4.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.antlr</groupId> 
      <artifactId>antlr4-maven-plugin</artifactId> 
      <version>4.5</version> 
      <type>maven-plugin</type> 
     </dependency> 

     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

</project> 
+0

相關(但不重複)http://stackoverflow.com/questions/2424015/maven-best-practice-for-generating-multiple-jars-with-different-filtered-classes – YMomb

回答

0

https://stackoverflow.com/a/2426271/800413解釋的,它往往是一個不好的做法,產生從同一項目多個工件/二進制文件。

對於你的情況,爲什麼不把多個項目共享主代碼庫作爲依賴關係並生成所需的二進制文件,併爲每個項目提供適當的庫?

+0

嗯是的,我可以做到這一點。有一個選項可以用一個命令同時創建多個mvn項目嗎?在這種情況下,應該在lib目錄中有一些庫(例如jar),並在bin目錄中有一些二進制文件。 – Waschbaer

+0

您可以創建一個Maven多項目結構,其中包含主項目和模塊。在主項目級別調用任何命令時,這將適用於所有子項目,因此您可以在單個「mvn package」命令中構建大量projetcs – YMomb

相關問題