我想从我的jar中排除一些类文件。我正在使用maven-assembly-plugin。它仍然添加文件。我没有收到任何错误

时间:2015-05-04 06:02:49

标签: maven jar maven-assembly-plugin

我对此代码没有任何错误。只是我想要排除的文件仍然被添加。我正在使用eclipse的maven插件

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <id>only</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <excludes>
                    <exclude>**/com/uiservices/controllers/*.*      </exclude>
                </excludes>
            </configuration>
        </execution>
    </executions>
</plugin>

3 个答案:

答案 0 :(得分:10)

maven-assembly-plugin无效。

你想要做的是覆盖程序集描述符jar-with-dependencies的配置,这是不可能的。

如果你想要做的是创建一个类似于程序集jar-with-dependencies创建的jar的jar,但没有你自己项目的某些特定类,你必须编写自己的程序集并在{{{ 1}}如下所示。

maven-assembly-plugin中的汇编:

src/assembly/jar-with-deps-with-exclude.xml

这将创建一个没有解包依赖项的程序集,并添加除了排除的类之外的类。

然后在你的pom.xml中:

<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-and-exclude-classes</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>false</useProjectArtifact>
            <unpack>true</unpack>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <outputDirectory>/</outputDirectory>
            <directory>${project.build.outputDirectory}</directory>
            <excludes>
                <exclude>com/uiservices/controllers/*.*</exclude>
            </excludes>
        </fileSet>
    </fileSets>
</assembly>

但如果您需要的是没有排除类的经典jar,您可以直接在<plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>only</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/assembly/jar-with-deps-with-exclude.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> 中排除它们:

maven-jar-plugin

答案 1 :(得分:0)

我遇到与maven-assembly-plugin类似的问题:

  1. 项目beans-conversion包含文件application.propertieslogback.xmllogback.xsd
  2. 项目extract-conversion还包含名为application.propertieslogback.xmllogback.xsd
  3. 的文件
  4. 要求extract-conversion.jar应包含beans-conversion.jar个内容,application.propertieslogback.xmllogback.xsd的{​​{1}}应覆盖extract-conversion.jar }。
  5. <强>解决方案:

    我们使用beans-conversion.jar解决了这个问题,如下面的extract-conversion的pom.xml。

    maven-shade-plugin

答案 2 :(得分:0)

使用Maven-shade-plugin 参考:Maven dependency: exclude one class

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.1</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
        <finalName>${project.artifactId}-jar-with-dependencies</finalName>
         <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
              <manifestEntries>
                 <Main-Class>com.taobao.arthas.core.Arthas</Main-Class>
              </manifestEntries>
             </transformer>
            </transformers>
          <filters>
            <filter>
              <artifact>*:termd-core</artifact>
              <excludes>
                <exclude>META-INF/services/io.termd.core.spi.ConfigProvider</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </execution>
    </executions>
  </plugin>