简体   繁体   English

Maven Maven-assembly-plugin jar-with-dependencies从最终jar中排除LICENSE.txt

[英]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.

相关问题 如何从 maven 程序集插件中排除依赖项:jar-with-dependencies? - How to exclude dependencies from maven assembly plugin : jar-with-dependencies? 使用Maven程序集插件组合Jar-with-dependencies和ZIP文件 - Combining Jar-with-dependencies and a ZIP file using the Maven assembly plugin Maven程序集插件不再产生jar-with-dependencies,为什么? - Maven assembly plugin not producing jar-with-dependencies any more, why? 无法使用maven-assembly-plugin设置最终的jar名称 - Can not set the final jar name with maven-assembly-plugin Maven程序集插件目标“ jar-with-dependencies”不包括子pom的jar文件 - Maven assembly plugin goal 'jar-with-dependencies' does not include a jar file from child pom Maven发布插件jar-with-dependencies - Maven release plugin jar-with-dependencies maven-assembly-plugin和jar名称冲突 - maven-assembly-plugin and jar name conflict maven-assembly-plugin:在开发过程中使用 config.properties,但在 jar-with-dependencies 上将 config.default.properties 打包为 config.properties - maven-assembly-plugin: use config.properties during development and but pack config.default.properties as config.properties on jar-with-dependencies 使用maven程序集插件创建包含胖jar的ZIP文件(jar-with-dependencies) - Using maven assembly plugin to create ZIP file containing a fat jar (jar-with-dependencies) Maven:如何使jar-with-dependencies排除“提供的”依赖? - Maven: How to have jar-with-dependencies exclude “provided” dependencies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM