I have to write a program for a class I'm taking, and he gave 开发者_如何学编程us an executable jar to run and compare our results with his.
However, I'm having trouble running it, even after reading some other related topics. I am given absolutely nothing else but the jar, which I can't extract.
I just want to run it somehow - either in a shell or on Eclipse.
== Sorry for the lack of specifics: It says I'm missing the Main-Class manifest attribute. I know when this happens you should go into the manifest and from picking around, I did notice that the manifest did NOT contain that attribute. I added it, but whenever I try to use jar uvf to add it back in, it just ignores it. "jar uvf EditDistance.jar META-INF/ ignoring entry META-INF/ ignoring entry META-INF/MANIFEST.MF "
Help please? :/
Have you tried:
java -jar filename.jar
?
You don't say what you've tried, or what errors you got...
if the manifest does not indicate the "main" class, but you know what that class is, then just do:
java -cp filename.jar com.example.MainClass
you can follow that with any program specific arguments if necessary. if you don't know the main class, then you'll need to ask the person who gave you the jar.
It is possible you were not given an executable jar. You may have to use jtahlborn's solution. If you can't figure out what to use for com.example.MainClass, you can try
jar -tf EditDistance.jar
This will give you a list of all files in the jar. Hopefully one is called either EditDistance.class or Main.class (with some prefix, so: "com/example/EditDistance.class").
If you see something like that, just translate slashes to dots, drop the .class suffix, and plug that in to jtahlborn's solution:
java -cp EditDistance.jar com.example.EditDistance
I had the same problem some time ago. Read this page, at the paragraph "Setting an Entry Point with the JAR Tool".
Try to execute this command: jar cfe app.jar MyApp MyApp.class
The e
option specify the application entry point.
Where:
app.jar
is the name of your jarMyApp
is the entry pointMyApp.class
is the name of your class.
At the end, type this command to execute the jar: java -jar app.jar
精彩评论