Could not find the main class: start.ServerGame. Program will exit. No logic!

Hi!



I need to run either the client or the server outside eclipse or I wont be able to see the output from the server.

So I tried running the fully working game using DOS and Jar.

Nothing works!

Both gives me the same error:

Could not find the main class: start.ServerGame. Program will exit.

Heres how the start.ServerGame.java looks like:
[java]package start;

import input.ContactManager;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;


import server.ServerListener;
import start.MainGame;

import com.jme3.network.Network;
import com.jme3.network.Server;
import com.jme3.system.AppSettings;



public class ServerGame extends MainGame{

Server myServer;
public static ServerGame app;
static int port = 3501;

public static void main(String[] args) {
app = new ServerGame();
}[/java]
So what the is wrong?

When I export to jar I even pick out the mainclass so that the compiler wont even have to think about it. So what is wrong?

In dos Iv tried the following commands:
java ServerGame
java ServerGame.class
javaw ServerGame
javaw ServerGame.class
java ServerGame.java
javaw ServerGame.java
javac ServerGame
javac ServerGame.java

Nada works.

If you deploied it as a jar Desktop application(JMP does it automatically), from CMD tipe:



cd path to the folder containing the jar



java -jar MyGame.jar



But you have to define in the manifest file the main class of the jar that in your case is ServerGame

yeah, just set the main class in the project settings.

Tried java -jar MyGame.jar

it gives Could not find the main class: start.ServerGame. Program will exit.

I found the manifest file, theres nothing wrong.

It says:Manifest-Version: 1.0

Main-Class: start.ServerGame



Im so stuck…

If you look in the jar, is that class in there? Are the dependencies in a subdirectory called lib relative relative to where you are running?



Is there anything else in the manifest file? I’m trying to decide if you built it yourself or let JMP do it.

I used eclipse to export as it is two projects. One is the base game and other is the Server game that use classes in basegame.

But yes, All files are in class but there is no lib folder.

But presumably your application uses other jar files… like jMonkeyEngine.jar. The bundle that JMP puts together will automatically add these to the classpath entry in the manifest. It’s the only real way to make java -jar work right.



…but if eclipse is easier for you then I’m sure you’ll figure out a way to make it work.

1 Like

So ur saying I have to import everything into the jme platform, then export it as jar?

Addez said:
So ur saying I have to import everything into the jme platform, then export it as jar?


What?

No, I'm saying that when you write a Java application that at some point that application will need access to its dependencies. For example, if you use a JME class then you will need the JME jar on your classpath.

When you run an application with -jar the only real way to specify the classpath is in the manifest.

And note: Java is not very good at accurately reporting which class is actually missing. If your main class refers to a class that can’t be found then sometimes Java will report your main class as not being found.

So, to fix this I simply copy the jMonkeyEngine.jar and everything in that folder into my jar?

And since you are using eclipse where you have to do everything manually that JMP would do automatically… you also have to add the jar to your manifest’s classpath entry.



…or don’t run with -jar and run with -cp and fully specify your classpath.



Getting the classpath right is pretty basic Java stuff… I imagine even Eclipse will have some help on it somewhere.