[英]Maven maven-assembly-plugin jar-with-dependencies exclude LICENSE.txt from final jar
I am using Maven to pack a single executable jar and I can't seem to figure out how to make it not put the LICENSE.txt and NOTICE.txt files inside it. 我正在使用Maven打包单个可执行jar,但似乎无法弄清楚如何不将LICENSE.txt和NOTICE.txt文件放入其中。 These files are found inside the final executable .jar, but I have no such files in my project directory.
这些文件位于最终的可执行文件.jar中,但我的项目目录中没有此类文件。
I tried multiple configurations that didn't work. 我尝试了多种无效的配置。 The one I am at now is the following:
我现在的位置如下:
Inside my pom.xml I have: 在我的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>
I also tried using inside the pom.xml 我也尝试在pom.xml内部使用
<descriptors>
<descriptor>/src/assembly/src.xml</descriptor>
</descriptors>
instead of 代替
<excludes>
<exclude>README*</exclude>
<exclude>LICENSE*</exclude>
<exclude>NOTICE*</exclude>
</excludes>
with the content of /src/assembly/src.xml: /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>
but for this I am getting 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]
但是为此,我
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]
How should I configure it to get a single executable jar with dependencies without those .txt files? 我应该如何配置它以获取具有不带那些.txt文件的依赖项的单个可执行jar?
I don't use filesets... 我不使用文件集...
I use this configuration, taken from here: 我使用以下配置:
http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html
<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>
<files>
<file>
<source>README.txt</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>LICENSE.txt</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>NOTICE.txt</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
</files>
</assembly>
This configuration should filter file you need at the moment of the generation of the ouput jar...so, it should filter also files that will be generated... 此配置应过滤生成输出jar时所需的文件...因此,它还应过滤将要生成的文件...
I hope this works for you... 我希望这对您有用...
The exclusions tag is to exclude jars dependencies. exclusions标记用于排除jar依赖项。 The dependencySet tag allows for an unpackOptions which has the options to include/exclude files when the dependencies are being unpacked.
DependencySet标记允许使用unpackOptions ,该选项具有在解压缩依赖项时包括/排除文件的选项。 So your assembly should look something like:
因此您的程序集应类似于:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<!-- TODO: a jarjar format would be better -->
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<unpackOptions>
<excludes>
<exclude>**/README.txt</exclude>
</excludes>
</unpackOptions>
</dependencySet>
</dependencySets>
</assembly>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.