[英]Java run jar from command line: Error could not find or load main class com.test.Main
Windows console command: Windows控制台命令:
c:\..path..>java -jar TestApp.jar
results in: Error could not find or load main class com.test.Main
结果:
Error could not find or load main class com.test.Main
I'm using IntelliJ 14 and my artifact layout looks like this: 我正在使用IntelliJ 14,并且我的工件布局如下所示:
TestApp.jar/
--client.jar <----- com.test.Main is located here
--jogl/
----gluegen.jar
----jogl-all.jar
--META-INF/
----manifest.mf
Manifest file info: 清单文件信息:
Main-Class: com.test.Main
Class-Path: client.jar;jogl/gluegen-rt.jar;jogl/jogl-all.jar;
but when I run code in IntelliJ, it is succesfull. 但是当我在IntelliJ中运行代码时,它就成功了。
I am afraid you can't, because default Classloader cannot load from a jar-within-a-jar. 恐怕您不能这样做,因为默认的Classloader无法从jar-in-a-jar加载。 I suppose IntelliJ will expand those jars and thus working.
我想IntelliJ会扩展这些jar并使其工作。
See here : Reference jars inside a jar 看到这里: 罐子里的参考罐子
But there is a solution. 但是有一个解决方案。 I use to create autorun-jars with dependencies using
maven-assembly-plugin
. 我使用
maven-assembly-plugin
创建具有依赖项的autorun-jars。 If I expand this jar I found that all jar dependencies are expanded inside the jar. 如果我扩展此jar,我发现所有jar依赖项都在jar内扩展。 This way, Classloader can load all classes.
这样,Classloader可以加载所有类。
If you don't use maven, IntelliJ must have an option to export project as autorun-jar or something similar. 如果您不使用maven,则IntelliJ必须具有将项目导出为autorun-jar或类似名称的选项。
If maven or exporting your project as autorun-jar is not ok for you, maybe One-JAR would serve your porpouse, but I have no experience with this project. 如果行不通或将您的项目导出为autorun-jar不合适,也许One-JAR会为您服务,但是我没有这个项目的经验。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.