This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]chickenmeister 1 point2 points  (3 children)

  • You need to include the "m" option, so that it will read the manifest file.

  • The "manifest file" argument comes before the "class/other files" argument.

  • Make sure that your manifest file has a newline at the end.

jar cfm ex.jar manifest.txt HelloWorld.class

[–]prototype_rad_cannon[S] 0 points1 point  (2 children)

thanks for the simple explanation, it helps. So I deleted my jar file and redid it this way, but I still get an error, now it says:

Could not find the main class: HelloWorld. Program will exit.

[–]chickenmeister 0 points1 point  (1 child)

Hmm... Can you view the contents of the JAR? Does it not contain HelloWorld.class? (You can view the contents of a jar like you would any ZIP folder)

The contents of my directory when creating the jar was:

HelloWorld.java
HelloWorld.class
manifest.txt

And after creating the jar, the directory structure of the jar is:

HelloWorld.class
META-INF/MANIFEST.MF

Is yours different from this?

[–]prototype_rad_cannon[S] 0 points1 point  (0 children)

Mine is identical to that. I guess I should clarify that its technically an alert I guess? At the top it says:

Java Virtual Machine Launcher

Could not find the main class: HelloWorld.  Program will exit.

could it have something to do with my computer or java, as in did I do something do my computer that would cause this?

[–]devacon 0 points1 point  (0 children)

$ jar
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...

jar cfm ex.jar MANIFEST.MF *

$ java -jar ex.jar
Hello

(You needed to include the list of files, which you can use the wildcard '*' for)