简体   繁体   English

Java -jar错误:找不到或加载主类

[英]Java -jar ERROR: could not find or load main class

I am making a 2d game, which I have compiled into a .jar to test if it works. 我正在制作2D游戏,已将其编译到.jar中以测试其是否有效。 When in run the jar file with java -jar command I get the following error: 使用java -jar命令运行jar文件时,出现以下错误:

Error: Could not find or load main class com.grizeldi.splatoon.Main

I know that there are many solutions here on StackOveflow, but I have tried updating java, messing with -cp... Nothing worked so far. 我知道在StackOveflow上有很多解决方案,但是我尝试过更新Java,弄乱了-cp ...到目前为止没有任何效果。

Code: github repo 代码: github回购

Help anyone? 帮助任何人?

EDIT1: I have my code on a USB stick, but I have tried moving it to C: and D: but nothing worked. EDIT1:我的代码放在USB记忆棒上,但是我尝试将其移至C:和D :,但没有任何效果。 EDIT2: I have added the .jar on the github. EDIT2:我在github上添加了.jar。

One way is to update the Manifest with the classpath to the other jars: 一种方法是使用其他jar的类路径来更新Manifest:

Class-Path: lib.jar

An alternative is to add the contents of the jars your main jar depends on to your main jar, so you have only one jar file. 一种替代方法是将主jar所依赖的jar的内容添加到主jar中,因此只有一个jar文件。 Make sure you don't add the jars themselves to the main jar, as nested jars won't work. 确保不要将罐子本身添加到主罐子中,因为嵌套罐子将无法工作。

When dealing with native libraries ( .so , .dll ), simply place these in the same directory as the jar. 处理本机库( .so.dll )时,只需将它们放在与jar相同的目录中即可。 The downside of this is that you have multiple files. 缺点是您有多个文件。 In that case, it might be easiest to just add a startup script ( .sh , .bat ), specifying the classpath and the classname of Main, aswell as a -Djava.library.path . 在这种情况下,仅添加启动脚本( .sh.bat ),指定classpath和Main的类名以及-Djava.library.path ,可能是最简单的。

There is also another way: extract the native library from the jar at runtime, save it to a temporary location, and load it explicitly. 还有另一种方法:在运行时从jar中提取本机库,将其保存到临时位置,然后显式加载它。 See here for more info on that. 有关更多信息,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM