Tôi có thể giải nén tệp zip qua plugin phụ thuộc maven, nhưng hiện tại tôi gặp sự cố bên trong tệp zip đó bao gồm các tệp zip khác và tôi cũng cần giải nén chúng. Tôi có thể làm cái này như thế nào?Giải nén các khóa bên trong bằng zip với Maven
Trả lời
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>
Bạn cũng có thể sử dụng phụ thuộc plugin. Có một mục tiêu để giải nén phụ thuộc (xem http://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html)
phản ứng này KHÔNG đúng, câu hỏi là về một tập tin với một zip bên trong, KHÔNG phải là một sự phụ thuộc. – Sergio
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
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 ý. –
@ 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
@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
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>
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". –
@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ọ –
Tôi mang nó rằng đây được đưa vào tập tin pom.xml của bạn? –
Có, đây là một phần của tệp 'pom.xml' của Maven. –
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ụ. –