无法找到或加载主类测试引起:java.lang.ClassNotFoundException:测试

发布于 2025-01-17 11:33:20 字数 457 浏览 1 评论 0原文

我是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

折戟 2025-01-24 11:33:20

这个问题可能是由很多原因造成的。我已经遇到过很多次了,大多数时候是因为你的类路径中有非英文字符或空格。
尝试将您的项目更改到其他目录。
另一方面,如果您使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文