运行maven生成的可执行jar时出错
我在执行 Maven 生成的可执行 jar 时遇到(一个奇怪的)问题:(
user@host$ java -server -jar MyJar.jar
Error
仅此而已!!!)
您知道这个错误之王来自哪里吗?
在我的 pom.xml 中,我将所有依赖项复制到 lib 文件夹:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${artifactId}-${version}/${artifactId}-${version}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
然后生成一个包含类路径的 .jar(+ 指向 lib 文件夹的前缀):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/${artifactId}-${version}/${artifactId}-${version}/bin</outputDirectory>
<finalName>MyJar</finalName>
<archive>
<manifest>
<mainClass>
com.company.package.Main
</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
生成的 MANIFEST.MF 似乎包含正确的类路径。
非常感谢您的帮助!
I'm having (a strange) problem when executing a maven generated executable jar:
user@host$ java -server -jar MyJar.jar
Error
(and nothing more than this!!!)
Do you have any idea what this king of error comes from ?
In my pom.xml, I copy all the dependencies to a lib folder with:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${artifactId}-${version}/${artifactId}-${version}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
And then I generate a .jar including the classpath (+ a prefix pointing to the lib folder):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/${artifactId}-${version}/${artifactId}-${version}/bin</outputDirectory>
<finalName>MyJar</finalName>
<archive>
<manifest>
<mainClass>
com.company.package.Main
</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
The generated MANIFEST.MF seems to contain the proper classpath.
Thanks a lot for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个错误并没有说明太多,这确实很奇怪。你使用的是Sun JDK吗?
不管怎样,我真的不明白如何将依赖项与您的设置捆绑到最终的 JAR 中,并且我不认为它包含所需的所有内容(当然我可能是错的)。
事实上,我什至不会尝试修复您当前的设置。要创建可执行 jar,您应该更喜欢程序集插件。请参阅例如这个最近的答案。请使用建议的配置修改您的
pom.xml
(这将需要 30 秒),然后重试。然后,请使用新的结果/错误、pom.xml
和清单更新您的问题。The error isn't saying much and this is indeed weird. Are you using Sun JDK?
Anyway, I don't really get how the dependencies get bundled into the final JAR with your setup and I don't think it contains everything required (I may be wrong of course).
Actually, I wouldn't even try to fix your current setup. To create an executable jar, you should prefer the assembly plugin. See this recent answer for example. Please modify your
pom.xml
with the suggested configuration (this will take 30 seconds) and try again. Then, please update your question with the new result/error, thepom.xml
and the manifest.我创建了一个新的 Maven 存储库,重建了所有 Maven 依赖项,并以某种方式解决了问题。
我不知道这是怎么发生的,因为我可以在没有罐子的情况下运行......
但无论如何还是感谢你的帮助
I created a new Maven repository, rebuilt all the maven dependencies and somehow the issue was solved.
I've no idea how this happened, because I was just able to run without the jar ...
But thanks for your help anyway