我希望从我的 jar 中排除一些类文件.我正在使用 maven-assembly-plugin.它仍然添加文件.我没有收到任何错误 [英] I wish to exclude some class files from my jar. I am using maven-assembly-plugin. It still adds the files. I dont get any error

查看:18
本文介绍了我希望从我的 jar 中排除一些类文件.我正在使用 maven-assembly-plugin.它仍然添加文件.我没有收到任何错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有收到此代码的任何错误.只是我想排除的文件仍然被添加.我正在使用 Eclipse 的 Maven 插件

I dont get any error with this code. Just that the file that I want to exclude still gets added. I am using the maven plugin for 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>

推荐答案

maven-assembly-plugin 不是这样工作的.

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

There what you want to do is override the configuration of the assembly descriptor jar-with-dependencies and that's not possible.

如果你想做的是创建一个类似于jar-with-dependencies程序集创建的jar,但没有自己项目的一些特定类,你必须自己编写程序集并在 maven-assembly-plugin 中调用它,如下所示.

If what you want to do is create a jar similar to the one created by the assembly jar-with-dependencies but without some specific classes of your own project, you have to write your own assembly and call it in the maven-assembly-plugin like what follows.

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>

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

This will create an assembly with no the dependencies unpacked and with your classes added except the ones excluded.

然后在你的 pom.xml 中:

And then in your 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>

<小时>

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

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>com/uiservices/controllers/*.*</exclude>
        </excludes>
    </configuration>
</plugin>

这篇关于我希望从我的 jar 中排除一些类文件.我正在使用 maven-assembly-plugin.它仍然添加文件.我没有收到任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆