2012-03-17 120 views
11

这就是我需要的。其他细节:我有一个src/bootstrap/java文件夹和常规的src/main/java文件夹。由于显而易见的原因,每个人都需要去一个单独的罐子。我是能够产生使用this自举罐子:如何从maven build jar中排除一组包?

<plugin> 
    <artifactId>maven-jar-plugin</artifactId> 
    <version>2.3.1</version> 
    <executions> 
     <execution> 
     <id>only-bootstrap</id> 
     <goals><goal>jar</goal></goals> 
     <phase>package</phase> 
     <configuration> 
      <classifier>bootstrap</classifier> 
      <includes> 
      <include>sun/**/*</include> 
      </includes> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

但经常罐子仍包括自举类。我正在用this answer编译引导类。

没有启动类生成myproject.jar的任何指示灯?

回答

16

你必须使用“默认罐子”为ID:

<plugin> 
    <artifactId>maven-jar-plugin</artifactId> 
    <version>2.3.1</version> 
    <executions> 
     <execution> 
     <id>only-bootstrap</id> 
     <goals><goal>jar</goal></goals> 
     <phase>package</phase> 
     <configuration> 
      <classifier>bootstrap</classifier> 
      <includes> 
      <include>sun/**/*</include> 
      </includes> 
     </configuration> 
     </execution> 
     <execution> 
     <id>default-jar</id> 
     <phase>package</phase> 
     <goals> 
      <goal>jar</goal> 
     </goals> 
     <configuration> 
      <excludes> 
      <exclude>sun/**/*</exclude> 
      </excludes> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
+2

你能告诉我,你已经习惯了运行特定的执行ID什么命令。 – 2014-03-26 14:59:28

+0

谢谢!有什么处理不得不指定'default-jar'? maven-jar-plugin会寻找它吗? – asgs 2014-04-04 05:49:54

0

也许用ProGuard?这是我用来去掉未使用的代码。它可以将它作为Maven插件添加到它的seems中。

1

我想你可以先看看这个,然后决定从一个pom生成两个罐子。

Maven best practice for generating multiple jars with different/filtered classes?

如果你仍然决定得到两个罐子,你也许可以做到这一点用这个。你必须指定适当的排除。

<build> 
    <plugins> 
     <plugin> 
     <artifactId>maven-jar-plugin</artifactId> 
     <executions> 
      <execution> 
      <id>only-bootstrap</id> 
      <goals><goal>jar</goal></goals> 
      <phase>package</phase> 
      <configuration> 
       <classifier>only-library</classifier> 
       <includes> 
       <include>**/*</include> 
       </includes> 
       <excludes> 
       <exclude>**/main*</exclude> 
       </excludes> 
      </configuration> 
      </execution> 
      <execution> 
      <id>only-main</id> 
      <goals><goal>jar</goal></goals> 
      <phase>package</phase> 
      <configuration> 
       <classifier>everything</classifier> 
       <includes> 
       <include>**/*</include> 
       </includes> 
       <excludes> 
       <exclude>**/bootstrap*</exclude> 
       </excludes> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
相关问题