2012-03-17 31 views
11

Đó là tất cả những gì tôi cần. Chi tiết bổ sung: Tôi có một thư mục src/bootstrap/java và thư mục src/main/java thông thường. Mỗi người cần phải đi đến một cái lọ riêng biệt vì những lý do rõ ràng. Tôi đã có thể tạo ra một hũ bootstrap bằng cách sử dụng this:Làm thế nào để loại trừ một tập hợp các gói từ 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> 

Nhưng bình thường vẫn bao gồm các lớp bootstrap. Tôi đang biên dịch các lớp bootstrap với this answer.

Mọi ánh sáng để tạo myproject.jar KHÔNG CÓ các lớp bootstrap?

Trả lời

16

Bạn phải sử dụng "mặc định-jar" cho 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

Ông có thể xin vui lòng cho tôi biết những gì lệnh bạn đã sử dụng để chạy id thực hiện cụ thể. –

+0

Cảm ơn! Thỏa thuận với việc phải chỉ định 'default-jar' là gì? Có maven-jar-plugin tìm nó? – asgs

0

Có thể sử dụng ProGuard? Đó là những gì tôi sử dụng để loại bỏ mã không sử dụng. Nó seems mà bạn có thể thêm nó như là một plugin Maven.

1

Tôi nghĩ bạn có thể xem xét điều này trước khi quyết định tạo hai lọ từ một pom.

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

Nếu bạn vẫn quyết định để có được hai lọ, bạn có thể có thể làm nó bằng cách sử này. Bạn phải chỉ định loại trừ thích hợp.

<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> 
Các vấn đề liên quan