在创建jar

系统教程 行业动态 更新时间:2024-06-14 17:01:34
在创建jar-with-dependencies时,Maven构建似乎会覆盖类(Maven build appears to be overwriting classes when creating jar-with-dependencies)

我正在使用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

更多推荐

本文发布于:2023-04-20 18:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/1535f50d84a73daf1a64ad5436e666f8.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!