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

use*_*190 9 jar maven maven-assembly-plugin

我没有得到这个代码的任何错误.只是我想要排除的文件仍然被添加.我正在使用maven插件进行eclipse

<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>
Run Code Online (Sandbox Code Playgroud)

Fab*_*ien 13

maven-assembly-plugin不起作用.

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

如果你想要做的是创建一个类似于程序集创建的jar jar-with-dependencies但没有你自己项目的某些特定类的jar ,你必须编写自己的程序集并按照后面的方式调用它maven-assembly-plugin.

汇编src/assembly/jar-with-deps-with-exclude.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>
Run Code Online (Sandbox Code Playgroud)

这将创建一个程序集,不会解压缩依赖项,并添加除了排除的类之外的类.

然后在你的pom.xml中:

<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>
Run Code Online (Sandbox Code Playgroud)

但是如果您需要的是没有排除类的经典jar,您可以maven-jar-plugin直接将它们排除在外:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>com/uiservices/controllers/*.*</exclude>
        </excludes>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)