无法找到或加载主类测试引起:java.lang.ClassNotFoundException:测试
我是Java的新手。我只是想从Java文件制作JAR文件,然后运行JAR文件。 我运行它时,我会遇到此错误。“找不到或加载主类mytest引起的:
罐子是创建的,
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class MyTest {
public static void main(String[] args) {
....
}
}
但是当 如下所示:
Manifest-Version: 1.0
Main-Class: MyTest
我在命令行中使用jar cmvf astest.jar mytest.java
创建了JAR文件。
有人可以帮我吗?
I am new to Java. I just wanted to make a jar file from a java file and then run the jar file. The jar is created but when I run it, I encounter this error "Could not find or load main class MyTest Caused by: java.lang.ClassNotFoundException: MyTest"
The MyTest.java file was simply something like this:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class MyTest {
public static void main(String[] args) {
....
}
}
My Manifest.MF file is like below:
Manifest-Version: 1.0
Main-Class: MyTest
And I created the jar file using jar cmvf Manifest.MF test.jar MyTest.java
in command line.
Could anyone please help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题可能是由很多原因造成的。我已经遇到过很多次了,大多数时候是因为你的类路径中有非英文字符或空格。
尝试将您的项目更改到其他目录。
另一方面,如果您使用 eclipse,您可能有多个主程序,并且存在问题。
如果您尝试了我告诉您的方法,但问题仍然存在,则可能是命令的问题。
祝你好运。
This problem can be due a lot of causes.I have had it many times , most of the time it is because your classpath has non-english characters or spaces.
Try to change your project to other directory.
On the other hand if you use eclipse you may have more than one main and there are problems with that.
If you try what I have told you and still the problem persists, it will be a problem with the command.
Good luck.