I have these fil开发者_开发技巧es board.class
and x4.class
(x4.class has main() method).
To jar these files, I wrote
jar cf x4.jar *.class
and got a x4.jar
file.
I copied this x4.jar file to my Desktop (on windows Vista) and double-clicked it. I am getting this error:
Failed to load Main-Class manifest attribute from
C:\Users\eSKay\Desktop\x4.jar
What should I do to make this file run as a jar executable (without installing any software)?
UPDATE: I used a manifest file to fix the problem. I have got the jar file I needeed and it is running fine if you do:
java -jar x4.jar
But, when I double click x4.jar nothing happens, I checked Task Manager and found that a javaw.exe is being started in the background, but it is not showing the output the original program was giving.
What can the problem be?
You need to create a manifest file which contains the Main-Class
attribute to specify its entry point. Then use the "m" flag in the jar command to specify it. For example, you might have a file called manifest.txt:
Manifest-Version: 1.0
Main-Class: x4
Note that you need to have an empty line at the end of the file, or the jar
tool won't process it properly, ignoring the final line silently.
Then run:
jar cfm x4.jar manifest.txt *.class
To test it, run:
java -jar x4.jar
I think @Jon is correct, just make sure you end the file with a CR/LF.
Setting an Application's Entry Point
Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
Or you can let the jar program automatically create the Main-Class attribute for you.
The 'e' flag (for 'entrypoint'), introduced in JDK 6, creates or overrides the manifest's Main-Class attribute. It can be used while creating or updating a jar file. Use it to specify the application entry point without editing or creating the manifest file. For example, this command creates app.jar where the Main-Class attribute value in the manifest is set to MyApp:
jar cfe app.jar MyApp MyApp.class
You can directly invoke this application by running the following command:
java -jar app.jar
If the entrypoint class name is in a package it may use a '.' (dot) character as the delimiter. For example, if Main.class is in a package called foo the entry point can be specified in the following ways:
jar cfe Main.jar foo.Main foo/Main.class
精彩评论