【发布时间】:2014-06-17 11:46:42
【问题描述】:
我正在使用 Maven 打包单个可执行 jar,但我似乎无法弄清楚如何使它不将 LICENSE.txt 和 NOTICE.txt 文件放入其中。这些文件可以在最终的可执行文件 .jar 中找到,但我的项目目录中没有此类文件。
我尝试了多种配置,但均无效。我现在的情况如下:
在我的 pom.xml 中我有:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
<excludes>
<exclude>README*</exclude>
<exclude>LICENSE*</exclude>
<exclude>NOTICE*</exclude>
</excludes>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>maven-assembly-plugin</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我也尝试在 pom.xml 中使用
<descriptors>
<descriptor>/src/assembly/src.xml</descriptor>
</descriptors>
而不是
<excludes>
<exclude>README*</exclude>
<exclude>LICENSE*</exclude>
<exclude>NOTICE*</exclude>
</excludes>
与/src/assembly/src.xml的内容:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>distribution</id>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<excludes>
<exclude>README*</exclude>
<exclude>LICENSE*</exclude>
<exclude>NOTICE*</exclude>
</excludes>
<!--useDefaultExcludes>false</useDefaultExcludes-->
</fileSet>
</fileSets>
</assembly>
但为此我得到Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (maven-assembly-plugin) on project DatabaseTaseng: Failed to create assembly: Error creating assembly archive distribution: A zip file cannot include itself -> [Help 1]
我应该如何配置它以获取具有依赖关系的单个可执行 jar 而没有那些 .txt 文件?
【问题讨论】:
-
这些文件在您的项目中的什么位置?
-
我没有。该插件似乎在打包时创建它们或从某些依赖项中获取它们。不知道是哪一个。
-
嗯,我不确定我是否相信你 :-) 打开文件 - 内容是什么?大概README.txt文件会包含线索。
-
抱歉,没有 README.txt 文件,只有 LICENSE.txt 和 NOTICE.txt。 LICENSE.txt 包含 2004 年 1 月的 Apache 许可证版本 2.0 和 NOTICE.txt
NOTICE file corresponding to section 4(d) of the Apache License, Version 2.0, in this case for the Apache XmlBeans distribution.。我使用 org.apache.poi.poi-ooxml 作为依赖项。是否可以将它们从中解压缩并留在存档的根目录中? -
是的,这很有可能。如果您删除这些文件,您可能会违反许可协议。我建议你离开他们!