0

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.

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.

Community
  • 1
  • 1

2 Answers2

0

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

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

DomV
  • 124
  • 4
0

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

Select a Launch Configuration which worked in Eclipse.

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

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

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

Zarathustra
  • 2,853
  • 4
  • 33
  • 62