我对此代码没有任何错误。只是我想要排除的文件仍然被添加。我正在使用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>
答案 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
类似的问题:
beans-conversion
包含文件application.properties
,
logback.xml
和logback.xsd
extract-conversion
还包含名为application.properties
,logback.xml
和logback.xsd
extract-conversion.jar
应包含beans-conversion.jar
个内容,application.properties
,logback.xml
和logback.xsd
的{{1}}应覆盖extract-conversion.jar
}。<强>解决方案:强>
我们使用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>