无法找到或加载主类ERROR [重复]

时间:2023-01-18 10:14:33

Possible Duplicate:
Error: Could not find or load main class

可能重复:错误:无法找到或加载主类

ive been working on some game code for a few hours now and it worked perfectly fine before, but then my eclipse decided to corrupt some stuff, I recovered it fully and it works perfectly in eclipse but when I try to run it via CMD or just as an Executable JAR I get Cannot find or load main class ERROR. Here is the current main method I have.

我已经在一些游戏代码上工作了几个小时,它之前工作得非常好,但是之后我的日食决定腐败一些东西,我完全恢复它并且它在eclipse中完美运行但是当我尝试通过CMD运行它或者只是作为一个可执行的JAR我得到无法找到或加载主类ERROR。这是我目前的主要方法。

public Game() {
    setMinimumSize(new Dimension(WIDTH * 2, HEIGHT * 2));
    setMaximumSize(new Dimension(WIDTH * 2, HEIGHT * 2));
    setPreferredSize(new Dimension(WIDTH * 2, HEIGHT * 2));
    frame = new JFrame(NAME);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(this, BorderLayout.CENTER);
    frame.pack();
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setIconImage(Icon);
}

private boolean running = false;
public InputHandler Inputs = new InputHandler(this);

public static void main(String[] args) {
    System.out.println("Starting");
    Game g = new Game();
    g.Start();
}

public void Start() {
    running = true;
    new Thread(this).start();
}

private static final int MapHeight = 40;

public void Stop() {
    running = false;

}

Im using windows 7 and JAVA 7. Hope I can get some help.

我使用Windows 7和JAVA 7.希望我能得到一些帮助。

2 个解决方案

#1


0  

If you want an executable jar, you need to have a MANIFEST.MF file that defines the main class to run...

如果你想要一个可执行jar,你需要有一个MANIFEST.MF文件来定义要运行的主类...

Main-Class: net.test.Class

If you want to run from the command line, you have to tell it what class to run, and probably the class path. This could go into a .bat

如果要从命令行运行,则必须告诉它要运行的类,以及类路径。这可能会进入.bat

#2


0  

In Eclipse click on the project -> right click -> Export. Select Runnable Jar file.

在Eclipse中单击项目 - >右键单击 - >导出。选择Runnable Jar文件。

Select a Launch Configuration which worked in Eclipse.

选择在Eclipse中工作的启动配置。

Eclispe will generate that MANIFEST.MF file for you into your jar file.

Eclispe会将您的MANIFEST.MF文件生成到您的jar文件中。

then oyu can run on your cmd: java -jar niceJarfile.jar and everything will work fine.

然后oyu可以运行你的cmd:java -jar niceJarfile.jar,一切都会正常工作。

If not open the jar file and look if the right main-class is mentioned there.

如果没有打开jar文件,看看那里是否提到了正确的主类。

#1


0  

If you want an executable jar, you need to have a MANIFEST.MF file that defines the main class to run...

如果你想要一个可执行jar,你需要有一个MANIFEST.MF文件来定义要运行的主类...

Main-Class: net.test.Class

If you want to run from the command line, you have to tell it what class to run, and probably the class path. This could go into a .bat

如果要从命令行运行,则必须告诉它要运行的类,以及类路径。这可能会进入.bat

#2


0  

In Eclipse click on the project -> right click -> Export. Select Runnable Jar file.

在Eclipse中单击项目 - >右键单击 - >导出。选择Runnable Jar文件。

Select a Launch Configuration which worked in Eclipse.

选择在Eclipse中工作的启动配置。

Eclispe will generate that MANIFEST.MF file for you into your jar file.

Eclispe会将您的MANIFEST.MF文件生成到您的jar文件中。

then oyu can run on your cmd: java -jar niceJarfile.jar and everything will work fine.

然后oyu可以运行你的cmd:java -jar niceJarfile.jar,一切都会正常工作。

If not open the jar file and look if the right main-class is mentioned there.

如果没有打开jar文件,看看那里是否提到了正确的主类。