我正在使用maven来构建一个jar-with-dependencies jar。 项目中的一个供应商jar文件类似地命名了具有不同大小写的类。 例如aM.class和am.class。
当构建创建“jar-with-dependencies”jar文件时,只存在aM.class。 am.class似乎已被覆盖或跳过。 每个类似命名的类文件都会发生同样的事情。
我们有几个解决方法,但我很好奇为什么maven构建的行为方式如此。 谢谢
我的pom:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.1</version> <configuration> <archive> <manifest> <mainClass>com.mytest.MyTest</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <dependencies> <dependency> <groupId>com.bloomberglp</groupId> <artifactId>blpapi3</artifactId> <version>3.10.1</version> </dependency> </dependencies>I'm using maven to build a jar-with-dependencies jar. One of the vendor jar files in the project has similarly named classes with different case. For example aM.class and am.class.
When the build creates the "jar-with-dependencies" jar file, only aM.class is present. am.class appears to have been overwritten or skipped. The same thing happens for every similarly named classes files.
We have a couple work-arounds, but I'm curious why the maven build is behaving this way. Thanks
My pom:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.1</version> <configuration> <archive> <manifest> <mainClass>com.mytest.MyTest</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <dependencies> <dependency> <groupId>com.bloomberglp</groupId> <artifactId>blpapi3</artifactId> <version>3.10.1</version> </dependency> </dependencies>最满意答案
使用maven-assembly-plugin会发生同样的类冲突问题,这个插件会将所有依赖jar提取到原始类中,并将它们组合在一起。它只在具有较少依赖性的项目中工作,对于具有许多依赖项的大型项目,它将导致Java类名冲突问题,请点击此处 。
如果你有很多可能会发生冲突的罐子,那么使用maven-shade-plugin会更好。 您还可以在shade插件中重新定位功能以明确避免冲突
Same class conflict issue will happen with maven-assembly-plugin, this plugin extracts all dependency jars into raw classes, and group it together.It works in project with less dependencies only, for large project with many dependencies, it will cause Java class name conflict issue, check here.
Better way to use maven-shade-plugin if you have many jars with potentially could conflict. You can also you relocating feature in shade plugin to explicitly avoid conflicts
更多推荐
发布评论