Question

Can anyone help me with this? I have not been able to find anything that answers this for exactly what I need. All the answers I find have to do with adding additional libraries to manifest files and what not.

Here's the situation:

I have written a game using NetBeans 6.9. The game is in Java. There are about 80 classes. All classes are contained in the default package. The game executes correctly. I've been working on this project for about 18 months and I always maintain executable code as I have developed the game.

What I did:

I needed to import something from a static class I'd written, into another class I was working on. In order to do that, I had to move everything out of the default package. I used NetBeans to refactor everything into a custom package.

What happened:

When I do a "clean and build", the project builds successfully. When I do a "run main project", I get the following error:

java.lang.NoClassDefFoundError: WarMachine
Caused by: java.lang.ClassNotFoundException: WarMachine
...stack trace
Could not find the main class: WarMachine. Program will exit.

I have checked the .jar file and I see that all the compiled .class files are there, including the main class (called WarMachine.class). All the .class files are in a directory called Machine (that was the package name I had NetBeans refactor everything into).

From what I have been able to find on the internet, the problem is that my manifest.mf file does not point to the correct location of the WarMachine.class file.

What does my manifest file need to say? I don't use any other libraries or anything like that. I have 78 classes, all of which are in the "Machine" package. Can anyone help me?

Thanks for your time!

Was it helpful?

Solution

You have to tell Netbeans where the main class file is. Right click on your project, select "Properties", then go to the "Run" tree element on the left.

You will now have a "Main Class" textbox on the right. Click "Browse" and select your main class. Netbeans should then fix the manifest file for you.

Run properties screenshot

In case you are curious, your manifest file inside the .jar file of the dist folder should have a line like this:

Main-Class: Machine.WarMachine

As an aside, it is considered standard practice to use lowercase letters for package names. You should call your package machine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top