使用 Assembly 插件生成的文件不会复制到 Maven 项目 zip
Generated files are not copied into Maven project zip with the Assembly Plugin
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
正在尝试使用 maven 插件以 zip 格式复制所有这些文件。
<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>
这意味着:"Include all files under etl_configs
"。这并不意味着 "Include all files recursively under 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 代码创建了一些文件,它在内部尝试复制到 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
正在尝试使用 maven 插件以 zip 格式复制所有这些文件。
<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>
这意味着:"Include all files under etl_configs
"。这并不意味着 "Include all files recursively under 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>