如何使用maven-assembly-plugin创建包含一些只读文件的zip存档

时间:2017-01-18 09:01:07

标签: maven zip readonly maven-assembly-plugin file-attributes

我有一个包含2个文件的项目( src / foo / a.txt src / foo / b.txt ),我想创建一个zip存档 b.txt 处于readonly状态。

这是我的环境:

  • Windows 7
  • JRE 1.8.0_112
  • Maven 3.3.3
  • maven-assembly-plugin 3.0.0
  • 7-Zip 9.20

这是我的pom.xml:

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.foo</groupId>
  <artifactId>foo-zip</artifactId>
  <version>0.1-SNAPSHOT</version>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals><goal>single</goal></goals>
          </execution>
        </executions>
        <configuration>
          <encoding>UTF-8</encoding>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptors>
            <descriptor>src/foo-assembly.xml</descriptor>
          </descriptors>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

这是我的汇编描述符:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

  <id>foo-zip</id>
  <includeBaseDirectory>false</includeBaseDirectory>

  <formats><format>zip</format></formats>

  <fileSets>
    <fileSet>
      <directory>src/foo</directory>
      <excludes><exclude>b.txt</exclude></excludes>
      <outputDirectory />
    </fileSet>
    <fileSet>
      <directory>src/foo</directory>
      <includes><include>b.txt</include></includes>
      <fileMode>0444</fileMode>
      <outputDirectory />
    </fileSet>
  </fileSets>
</assembly>

当我解压缩生成的存档,并打开b.txt的属性时,&#34; readonly&#34;未选中复选框。

我知道: Maven assembly plugin not applying fileMode on unpacked dependencySetmaven assembly plugin do not set file attributes,但他们对我帮助不大。

我尝试了各种fileMode值(0444或0544),但我无法在readonly模式下解压缩文件。

有什么想法吗?

0 个答案:

没有答案