英文:
"Could not find or load main class" when running executable JAR via "java -jar"
问题
以下是翻译好的内容:
这是我执行 java -version
命令的输出:
openjdk版本 "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
当我尝试用 java -jar
执行我的文件时,会显示一个找不到/加载不了主类的消息。我确定这个在 Windows 上是可以工作的,因为我在 Windows 上试过并且成功了。我在 Linux 机器上也试过,也成功了。我不知道我做错了什么,顺便说一下,我是 Linux 的初学者。
我尝试从我的计算机中移除所有的 Java 相关内容,然后重新安装 Java 8 版本,但仍然不起作用。
这是我尝试执行命令的方式。我在 /opt
目录下有一个 Java,用那个 Java 可以让我打开它。
以管理员身份运行时,错误是一样的,只不过是用西班牙语显示的。
MANIFEST 文件
Ant-Version: Apache Ant 1.9.7
Created-By: 1.8.0_231-b11 (Oracle Corporation)
Class-Path: lib/hamcrest-junit-2.0.0.0.jar lib/java-hamcrest-2.0.0.0.j
ar lib/testFx-3.1.0.jar lib/testfx-core-4.0.13-alpha.jar lib/testfx-j
unit-4.0.13-alpha.jar lib/javax.ws.rs-api-2.0.jar lib/asm-all-repacka
ged-2.2.0-b21.jar lib/cglib-2.2.0-b21.jar lib/guava-14.0.1.jar lib/hk
2-api-2.2.0-b21.jar lib/hk2-locator-2.2.0-b21.jar lib/hk2-utils-2.2.0
-b21.jar lib/javax.annotation-api-1.2.jar lib/javax.inject-2.2.0-b21.
jar lib/javax.servlet-api-3.0.1.jar lib/jaxb-api-2.2.7.jar lib/jersey
-entity-filtering-2.5.1.jar lib/jersey-media-moxy-2.5.1.jar lib/org.o
sgi.core-4.2.0.jar lib/osgi-resource-locator-1.0.1.jar lib/persistenc
e-api-1.0.jar lib/validation-api-1.1.0.Final.jar lib/jersey-client.ja
r lib/jersey-common.jar lib/jersey-container-servlet.jar lib/jersey-c
ontainer-servlet-core.jar lib/jersey-server.jar lib/eclipselink.jar l
ib/UtillitiesProject.jar
X-COMMENT: 主类将会被构建自动添加
Main-Class: windowsapplication.WindowsAppicationReto2
有任何想法吗?
英文:
Thats the output when i execute java -version
> openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
When i tried to execute my file with java -jar shows me a message that can't found/load the main class. I'm sure that this works because i try it in Windows and works done. I tried in a linux machine and works too. I don't know what i am doing bad, I'm beginner with linux by the way.
I tried to remove all the java stuff from my computer and reinstall java 8 version but still not works.
Thats how i tried to execute the command. I have one java in opt and with that one let me open it.
As admin is the same error but in spanish.
MANIFEST
Ant-Version: Apache Ant 1.9.7
Created-By: 1.8.0_231-b11 (Oracle Corporation)
Class-Path: lib/hamcrest-junit-2.0.0.0.jar lib/java-hamcrest-2.0.0.0.j
ar lib/testFx-3.1.0.jar lib/testfx-core-4.0.13-alpha.jar lib/testfx-j
unit-4.0.13-alpha.jar lib/javax.ws.rs-api-2.0.jar lib/asm-all-repacka
ged-2.2.0-b21.jar lib/cglib-2.2.0-b21.jar lib/guava-14.0.1.jar lib/hk
2-api-2.2.0-b21.jar lib/hk2-locator-2.2.0-b21.jar lib/hk2-utils-2.2.0
-b21.jar lib/javax.annotation-api-1.2.jar lib/javax.inject-2.2.0-b21.
jar lib/javax.servlet-api-3.0.1.jar lib/jaxb-api-2.2.7.jar lib/jersey
-entity-filtering-2.5.1.jar lib/jersey-media-moxy-2.5.1.jar lib/org.o
sgi.core-4.2.0.jar lib/osgi-resource-locator-1.0.1.jar lib/persistenc
e-api-1.0.jar lib/validation-api-1.1.0.Final.jar lib/jersey-client.ja
r lib/jersey-common.jar lib/jersey-container-servlet.jar lib/jersey-c
ontainer-servlet-core.jar lib/jersey-server.jar lib/eclipselink.jar l
ib/UtillitiesProject.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: windowsapplication.WindowsAppicationReto2
Any idea?
答案1
得分: 1
答案非常简单:您的清单中有一个拼写错误,正如您的屏幕截图和您发布的清单中都清楚地看到的:
请将
Main-Class: windowsapplication.WindowsAppicationReto2
更改为
Main-Class: windowsapplication.WindowsApplicationReto2
应用中的“l”为小写的“L”。
英文:
The answer is very simple: You have a typo in your manifest, as can clearly be seen both in your screenshots and in the manifest you posted itself:
Please change
Main-Class: windowsapplication.WindowsAppicationReto2
to
Main-Class: windowsapplication.WindowsApplicationReto2
App~l~ication with a lower-case "L".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论