2010-07-16 21 views

Trả lời

42

Bạn có thể giải nén bất kỳ tập tin sử dụng kiến ​​Plugin nhiệm vụ Á hậu:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.6</version> 
    <executions> 
     <execution> 
      <id>prepare</id> 
      <phase>validate</phase> 
      <configuration> 
       <tasks> 
        <echo message="prepare phase" /> 
        <unzip src="zips/archive.zip" dest="output/" /> 
        <unzip src="output/inner.zip" dest="output/" /> 
        <unzip dest="output"> 
         <fileset dir="archives"> 
         <include name="prefix*.zip" /> 
         </fileset> 
        </unzip> 
       </tasks> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
+0

Tôi mang nó rằng đây được đưa vào tập tin pom.xml của bạn? –

+0

Có, đây là một phần của tệp 'pom.xml' của Maven. –

+0

Làm cách nào để bạn có thể giải nén một tệp phù hợp với cụm từ thông dụng? Ví dụ.

21

Sử dụng ANT không mát nữa;) mã

http://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html

mẫu cho giải nén zip archive.zip) tập tin (:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>unpack</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>unpack</goal> 
      </goals> 
      <configuration> 
       <artifactItems> 
        <artifactItem> 
         <groupId>foo</groupId> 
         <artifactId>archive</artifactId> 
         <version>1.0-SNAPSHOT</version> 
         <type>zip</type> 
        </artifactItem> 
       </artifactItems> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

Lưu trữ tệp.zip phải được cài đặt vào kho lưu trữ maven trước tiên. Ví dụ: với tác vụ Attach artifact org.codehaus.mojo:build-helper-maven-plugin:build-helper:attach-artifact

+16

Nhưng điều đó chỉ giải nén các đồ tạo tác, chứ không phải các tệp tùy ý. –

+0

@ OndraŽižka Với maven bạn có thể xử lý bất kỳ tập tin "tùy ý" như tạo tác, chỉ cần nhìn vào 'build-helper: attach-artifact'. – MariuszS

+2

@MariuszS làm thế nào để làm điều đó với một tập tin tùy ý trên hệ thống tập tin địa phương? – tojofo

7

TrueZIP Maven Plugin cũng hoạt động tốt. cấu hình mẫu:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>truezip-maven-plugin</artifactId> 
    <version>1.2</version> 
    <executions> 
     <execution> 
      <id>copy-package</id> 
      <goals> 
       <goal>copy</goal> 
      </goals> 
      <phase>package</phase> 
      <configuration> 
       <verbose>true</verbose> 
       <fileset> 
        <directory>outer.zip</directory> 
        <outputDirectory>${project.build.directory}/outer</outputDirectory> 
       </fileset> 
       <fileset> 
        <directory>${project.build.directory}/outer/inner.zip</directory> 
        <outputDirectory>${project.build.directory}/inner</outputDirectory> 
       </fileset> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

Official examples

+1

Codehaus đang ngừng hoạt động, vì vậy các liên kết giờ đây sẽ chuyển đến trang "chúng tôi đang sắp xếp lại". –

+0

@palacsint giấy phép của plugin ở trên là gì, tôi không thể tìm thấy nó trong tài liệu của họ –