Java 代码创建了一些文件,并在内部尝试复制到 zip 中。但除某些文件外,所有文件均已复制。我无法找出这背后的原因。
我正在添加我尝试使用其权限复制的文件夹的目录结构以及它在目标文件夹(zip 文件)中复制的内容。
目录结构及其权限 -
XYZ-MacBook-Pro:etl_configs XYZ$ pwd FILE_PATH_LOCATION/etl_configs XYZ-MacBook-Pro:etl_configs XYZ$ ls -l * -rw-r--r-- 1 XYZ staff 980 Jun 26 01:02 etl-spec.json -rwxr-xr-x 1 XYZ staff 2037 Jun 15 19:04 etl-without-transformation.json feeds: total 16 -rw-r--r-- 1 XYZ staff 612 Jun 26 00:54 feed_1.json -rw-r--r-- 1 XYZ staff 616 Jun 26 01:02 feed_2.json tables: total 16 -rw-r--r-- 1 XYZ staff 878 Jun 26 00:54 table_1.json -rw-r--r-- 1 XYZ staff 880 Jun 26 01:02 table_2.json
Trying to copy all these files in zip using maven plugins.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<descriptor>${project.basedir}/zip.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
zip.xml 文件包含 -
<fileSet>
<directory>${project.basedir}/etl_configs</directory>
<outputDirectory>/etl_configs</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
目标 zip 文件包含-
XYZ-MacBook-Pro:etl-without-transformation-template-1.0-SNAPSHOT XYZ$ pwd
FILE_PATH_LOCATION/target/etl-without-transformation-template-1.0-SNAPSHOT-zip/etl-without-transformation-template-1.0-SNAPSHOT
XYZ-MacBook-Pro:etl-without-transformation-template-1.0-SNAPSHOT XYZ$ ls -l etl_configs/*
-rwxr-xr-x 1 XYZ staff 980 Jun 26 01:02 etl_configs/etl-spec.json
-rwxr-xr-x 1 XYZ staff 2037 Jun 15 19:04 etl_configs/etl-without-transformation.json
etl_configs/feeds:
etl_configs/tables:
理想情况下,它应该复制 zip 中的整个文件夹。但这并没有发生。
最佳答案
该问题与您使用 <includes>
的方式有关在你的程序集描述符中。您当前使用的是
<fileSet>
<directory>${project.basedir}/etl_configs</directory>
<outputDirectory>/etl_configs</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
这意味着:“包含 etl_configs
下的所有文件”。这并不意味着“递归地包含 etl_configs
下的所有文件”。这是因为您正在使用 <include>*</include>
:maven-assembly-plugin
使用 Ant 风格的模式,并且在 Ant 中 *
matches zero or more characters within a path name ,不跨越目录边界。
因此,要递归地包含所有文件,您可以使用:
<fileSet>
<directory>${project.basedir}/etl_configs</directory>
<outputDirectory>/etl_configs</outputDirectory>
<includes>
<include>**</include>
</includes>
</fileSet>
但是,this is the default behaviour :
When
<include>
subelements are present, they define a set of files and directory to include. If none is present, then<includes>
represents all valid values.
所以你可以:
<fileSet>
<directory>${project.basedir}/etl_configs</directory>
<outputDirectory>/etl_configs</outputDirectory>
</fileSet>
关于java - 生成的文件不会使用 Assembly Plugin 复制到 Maven 项目 zip 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38032745/