【问题标题】:Maven: creating an archive (zip or jar) file containing files outside the project?Maven:创建包含项目外部文件的存档(zip 或 jar)文件?
【发布时间】:2013-01-31 15:53:56
【问题描述】:

我目前正在开发一个基于 Maven 的项目,在该项目中我有生成 PDF 文件的单元测试,比如说“C:/result”目录(我绝对不希望在任何目录中创建这些文件我的项目)。

使用 maven-assembly 插件,是否可以创建一个归档文件(最好是 zip 或 jar)来收集在“C:/result”中生成的文件?

基本上,我的目标是在每次部署项目的新版本时将此存档作为常规人工制品上传到 Nexus 服务器上。

提前致谢。

【问题讨论】:

  • 我不知道为什么生成的PDF文件不能直接进入target
  • 事实上,我也不知道为什么。这只是我从工作人员那里得到的限制,但我肯定会问他确切的原因。

标签: maven maven-3 maven-assembly-plugin


【解决方案1】:

您需要定义类似于以下内容的程序集描述符:

<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>bin</id>
    <formats>
        <format>zip</format>
    </formats>
    <baseDirectory>C:/</baseDirectory>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>results</directory>
            <outputDirectory>./doc</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

保存例如作为src/assembly/bin.xml,它将从pom 中引用。 pom 将包含在 build 部分中:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <id>out</id>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/bin.xml</descriptor>
                </descriptors>
            </configuration>
            <phase>verify</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

更多信息请参见maven assembly documentation

【讨论】:

  • 我使用类似的程序集描述符创建了我想要的存档文件,但现在我想将它与其他工件一起上传到 Nexus 服务器。
  • 这正是我所需要的。太糟糕了,我在早些时候浏览 SO 时没有碰到这个问题。无论如何,非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-07
  • 2013-08-05
  • 2011-01-16
  • 2015-01-21
  • 1970-01-01
  • 2018-07-23
  • 2014-08-07
相关资源
最近更新 更多