CustardBun
CustardBun

Reputation: 3867

Executable Jar Can't Run? (Without permissions to access the code)

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? :/

Upvotes: 0

Views: 1565

Answers (4)

ccoakley
ccoakley

Reputation: 3255

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

Upvotes: 0

Alberto Solano
Alberto Solano

Reputation: 8227

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 jar

  • MyApp is the entry point

  • MyApp.class is the name of your class.

At the end, type this command to execute the jar: java -jar app.jar

Upvotes: 0

jtahlborn
jtahlborn

Reputation: 53694

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.

Upvotes: 1

tim_yates
tim_yates

Reputation: 171154

Have you tried:

java -jar filename.jar

?

You don't say what you've tried, or what errors you got...

Upvotes: 2

Related Questions