Running .jar error main class not found.

So I made a simple game for a friend, compiled it into a jar which runs fine on my PC. However my friend gets an error main class not found.

They use a Mac and I compiled on a Windows PC if that’s of any relevance.

I compiled using “jar -cvmf manifest.txt nameOfMainProgramFile.jar *.class”

manifest.txt = Main-Class: Game

What is usually the main cause of this error on a mac? Could it be a problem with their java install?

Thank you for any help you can provide

Ask your friend to show you the stackstrace. We just can’t guess from the little information you provide. What is your Java version? What is your friend’s java version?

Thanks for getting back to me. How can I get the stacktrace on a mac?

I have the latest version of java. I am not sure about the friend. I will try to find out.

Stackstrace is just the output of the error message that Java outputs to the Terminal. Ask your friend to launch your application from the terminal like this [icode]java -jar yourjar.jar[/icode]

You might also consider posting a link to your jar for us to try out ourselves, that way we can see the error directly.

Do you not see the error when you run the jar?

Could be a case-sensitivity issue? Just speculating… Windows is forgiving of case errors, other OSs aren’t.

With the class specified in manifest.txt and the actual name of the class? I don’t think so…

Is there some code I can add to record the stacktrace? It’s being opened simply by double clicking the jar, the error occurs in a window. (I can’t physically use said friends PC, and they can’t really be stuffed to mess around opening stuff through the terminal, which can’t be blamed really)

Edit: when sister comes over I will use her mac and see if I can find out more

I’ll update soon

Not really- the error presumably happens before any of your code actually runs.

You could wrap your jar in another main class that runs your actual main class… but you’d have the same difficulty of defining the main class then.

Just post a link to the jar for us to try.

Is the main class in the root of the jar, or in a sub-directory/package? If it isn’t in the root, try specifying the package in manifest. If it won’t work, I don’t know how to help ya. :-\

maybe extra char occurred in manifest: trailing space, \r\n -> \r, eof?

There might have been a newline?

These are the errors I get on a mac:

Exception in thread “main” java.lang.UnsupportedClassVersionError
at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

That means your friend is using an older version of Java.

Hi

Rather use my own tool (JNDT) to package your game as an .app file or PackR, there is a simple example of use here:

Then, your friend will use the JRE packaged with your game and it will work if his Mac isn’t too old.

Yeah I would use something like that, but the problem is I want the file size to be small.

But that’s definitely an option.

Should I install an older version of java, and then compile?

Also, the error on my sisters mac and my friends mac, read differently. Does anyone know how to explain this?

I guess if there’s an exception in thread ‘main’ then main class can’t be found? Iunno???

The exact problem is that your sister’s and your friend’s Macs has old version of Java installed. You have to ask them to upgrade their Java installation. If you are still in doubt, provide us a download, I also use a mac, so we can test that.

Well I am not sure whether or not I should still be in doubt so I was asking if specifically those two seemingly unrelated error messages were in fact saying the same thing.

You can minimize the JRE but you can’t have the cake and eat it.

What version of Java are you using? What version of Java are your friends using?

You can set the Java compiler to output code that’s compatible with older versions of Java. How you do this depends on how you’re compiling your code.

Google “java compiler compliance level” for more info.

Simply through the command line. I’ll have a look.

How small can I make the JRE?

Don’t expect less than 10 MB except if you use this JEP:
http://openjdk.java.net/jeps/148