我想知道是否可以在使用 mvncompile 时“打包”依赖项。
当我使用 mvn install 编译程序时,我确实得到了预期的干净且良好的结果,但在将其打包到 .jar 中后,突然出现缺少类异常。
我读到这可能是由构建和包类路径的差异引起的,但我无法修复它。
非常感谢。
最佳答案
这听起来像是您正在寻找的可执行阴影 jar。
如何制作可执行jar?
https://github.com/renfeng/elo-rating/blob/master/cli/pom.xml#L32-L51
如何制作阴影 jar ?
https://github.com/renfeng/elo-rating/blob/master/cli/pom.xml#L52-L67
或者,您也可以
- 与程序集插件的软件包依赖关系,以及
https://github.com/renfeng/elo-rating/blob/master/cli/src/main/assembly/dist.xml#L30-L33
- 使用指定的类路径启动。
https://github.com/renfeng/elo-rating/blob/master/cli/elo#L4
或者,您可以选择中间的某个位置,就像我的 github 示例项目一样。
关于java - 是否可以将依赖项打包到.jar中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47026270/