简体   繁体   English

Java JAR 找不到主 class

[英]Java JAR Couldn't find main class

64x Intel processor 64x 英特尔处理器
Kubuntu 19.04 on Linux 5.0.0-27 Linux 5.0.0-27 上的 Kubuntu 19.04
OpenJDK 1.8.0_222 OpenJDK 1.8.0_222


In the last hour I have set up my project folder, created scripts for automatic compiling and for back-ups etc...在过去的一个小时里,我设置了我的项目文件夹,创建了用于自动编译和备份等的脚本......

Finally I got it working, I get the JAR file.最后我得到了它,我得到了 JAR 文件。 The problem is that I can't run it.问题是我无法运行它。 I know that this is very common problem, but I don't see any compiling errors, mistakes nor typos.我知道这是很常见的问题,但我没有看到任何编译错误、错误或拼写错误。 I'm totally lost.我完全迷路了。

Even using java -jar TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint and java -cp TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint show the same error. Even using java -jar TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint and java -cp TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint show the same error.

Error: Could not find or load main class com.ydsoftware.taskcalender.EntryPoint

My source file structure:我的源文件结构:

com
  ydsoftware
    taskcalender
      EntryPoint.java (contains main method)    

My JAR file structure:我的 JAR 文件结构:

META-INF
  MANIFEST.MF 
com
  ydsoftware
    taskcalender
      EntryPoint.class (contains main method)   

MANIFEST.MF contents (inside the JAR file): MANIFEST.MF 内容(在 JAR 文件中):

Manifest-Version: 1.0
Created-By: 1.8.0_222 (Private Build)
Main-Class: com.ydsoftware.taskcalender.EntryPoint
Class-Path: lib/MX%20Engine.jar
/ blank /
/ blank /

Can you try below in CMD or through batch file as per your convenience您可以根据您的方便在 CMD 或通过批处理文件尝试下面

Generic: java -cp your_jar_name.jar package_name.classname通用:java -cp your_jar_name.jar package_name.classname

as per your class: java -cp TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint根据您的 class: java -cp TaskCalender.jar Z4D236D9A2D102C5C5FE6AD1C50

SOLVED解决了

The problem was that Class-Path: lib/MX%20Engine.jar was missing because my computer had shut down unexpectably (because our power was cut off for some reason) and the changes to MANIFEST.MF were lost.问题是Class-Path: lib/MX%20Engine.jar丢失,因为我的计算机意外关闭(因为我们的电源由于某种原因被切断)并且对 MANIFEST.MF 的更改丢失了。 Didn't even notice.甚至没有注意到。

Still, it should say something along the lines of Class not found or unexcepted token instead of saying Could not find or load main class which made finding the problem harder.尽管如此,它应该说一些类似于Class not found或 unexcepted unexcepted token的内容,而不是说Could not find or load main class ,这使得发现问题变得更加困难。

Thank you to everyone who tried to help me!感谢所有试图帮助我的人!

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

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