java - 如何使用 maven package 命令制作 zip 存档时添加其他目录?

标签 java maven build packaging

我有以下项目 maven 项目:

enter image description here

我想在 mvn package 命令创建的 zip 中添加资源场景目录。

我在 pom.xml 中添加了 zip.xml 程序集和所需的插件:

src/main/assembly/zip.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>zip</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>./</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>./</outputDirectory>
            <includes>
                <include>/dependency-jars/</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

这是pom.xml:

<packaging>jar</packaging>
<dependencies>
     .....
</dependencies>
<build>

    <testResources>
        <testResource>
            <directory>${project.basedir}/config</directory>
        </testResource>
    </testResources>


    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerVersion>${sourceVersion}</compilerVersion>
                <source>${sourceVersion}</source>
                <target>${targetVersion}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <finalName>zip-with-dependencies</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptors>
                            <descriptor>src/main/assembly/zip.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>test-compile</id>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <source>${sourceVersion}</source>
                <target>${targetVersion}</target>
                <showWeaveInfo>true</showWeaveInfo>
                <complianceLevel>${sourceVersion}</complianceLevel>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>com.qmetry</groupId>
                        <artifactId>qaf</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>${testSuiteFile}</suiteXmlFile>
                </suiteXmlFiles>
                <reportsDirectory>${test.results.dir}/${run.time}</reportsDirectory>
                <systemPropertyVariables>
                    <org.uncommons.reportng.xml-dialect>testng</org.uncommons.reportng.xml-dialect>
                    <org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output>
                    <log4j.configuration>file:///${resource.dir}/log4j.properties</log4j.configuration>
                    <outputDir>${output.dir}</outputDir>
                    <test.results.dir>${output.dir}/html</test.results.dir>
                    <json.report.root.dir>${test.results.dir}</json.report.root.dir>
                    <json.report.dir>${output.dir}/json</json.report.dir>
                    <selenium.screenshots.dir>${output.dir}/img</selenium.screenshots.dir>
                    <selenium.screenshots.relative.path>../img</selenium.screenshots.relative.path>
                </systemPropertyVariables>
            </configuration>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>aspectj-maven-plugin</artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>test-compile</goal>
                                        <goal>compile</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

任何帮助将不胜感激。谢谢

最佳答案

我明白了。我们可以使用<testResources>pom.xml添加所需的目录。例如

<testResources>
    <testResource>
        <directory>${project.basedir}/resources</directory>
    </testResource>
</testResources>

关于java - 如何使用 maven package 命令制作 zip 存档时添加其他目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61664552/

相关文章:

java - 不接收对特定 bean 的请求

java - 为什么我的虚拟机中的 R 计算不一致?

android - 找不到 com.opentok.android :opentok-android-sdk

grails - 自定义 Grails 环境?

Angular 6 构建无法加载资源

visual-studio - 如何在 MFC 中为不同的构建目标使用不同的资源文件

java - 在 jira 工作流 validator 中获取当前用户

java - ssh4 延迟初始化异常

java - PowerMockito:检测到未完成的 stub (未完成的 stub 异常)

java - Hadoop 2.2.0 上的 HBase 0.94.4