I've created a jar file like this:

jar cfmv Manifest.mf RoboPlot.jar RoboPlot.class ImagePlotter.class

The manifest.mf file looks like this:


For some reason, when I use this command to run it,
java -jar RoboPlot.jar

it tells me that the main class could not be found

I also tried this:

Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems Inc.)

and it didn't work either.

Maybe another stupid idea: check that your RoboPlot class has a method with the exact signature required for a main method (i.e. public static void main(String[] args) ).

I read something that said the main class cannot contain any package statements....Is this true? If it is, that's my problem, because I import swing, awt, and all that good stuff.

Java is all about packages.
Maybe the reason it cannot find the class is that you didn't put it in a package?
Default package (a.k.a. no package) is dangerous and should be avoided.

Should I put all of my classes in a package? I mean, is that what they meant, because I took it as I needed to create a whole new class, that only created an instance of the main one.

You should always use packages. It's not officially mandated by the JLS but in practice it's the only way to go.
For example you can not import a class that is not in a package from any class that is in a package. You can also not create instances of it (though there are ways to do so using reflection, but that's rather convoluted).

Yeah I tried that..I'm getting an invalid header error, and I've tried all sorts of combinations to see if I could get it to work..But, I did add the blank line at the end.

Hi everyone,

I noticed that you did no have a space at the :


I think it should be

Main-Class: RoboPlot

Try this

(start at beginning of file)
Manifest-Version: 1.0
Main-Class: RoboPlot

Let me know if it works

Richard West

Thank you for replying, unfortunately this didn't work(Don't know why). I added the space between the :, and a blank line at the end. It still gave me an invalid header field when ran. You have anymore suggestions or thoughts about this?

after more than 6 years, I'm pretty sure that, even if the OP hasn't finished yet, he doesn't really care anymore.

don't revive dead threads, it's useless and a waste of time.

could one of the admins please close this thread?

This article has been dead for over six months. Start a new discussion instead.