我希望从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
问题描述
此代码没有任何错误.只是我要排除的文件仍然被添加.我正在将Maven插件用于Eclipse
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
中排除它们:
But if what you need is your classical jar without excluded classes, you can exclude them in the maven-jar-plugin
directly :
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>com/uiservices/controllers/*.*</exclude>
</excludes>
</configuration>
</plugin>
这篇关于我希望从jar中排除一些类文件.我正在使用maven-assembly-plugin.它仍然添加文件.我没有任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!