java - 生成的文件不会使用 Assembly Plugin 复制到 Maven 项目 zip 中

标签 java maven maven-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

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/

相关文章:

java - 在带 Hibernate 的 JPA 2 中强制传递持久性顺序?

java - 函数和谓词参数不明确?

maven - 从Maven迁移到Gradle:WAR构建任务的 “gradle build”失败

java - 使用 maven-assembly-plugin 创建两个可执行的 jar

maven - 使用资源中的依赖项覆盖属性文件

maven - 如何在多模块 Maven 项目中使用 Maven 程序集插件

java - 如何在处理之前拦截 Spring Security 登录请求?

java - SWT 检查表禁用复选框

java - 使用 ProGuard,使用通配符保留类字段

java - 使用 Maven 在 IntelliJ IDEA 中构建 JavaFX 应用程序