tags:

views:

60

answers:

3

I'm trying to run a JAR file and nothing happens? Any idea why? Did I maybe do the export wrongly?

Some guidelines would be very welcome!

+4  A: 

Jar files can only be executed if they contain a META-INF/MANIFEST.MF that specifies the main class (entry point) into your application. Otherwise you have to specify the class manually on the command line.

e.g. it contains

Main-Class: com.mycompany.App

Then you can just say:

java -jar MyApp.jar

Normally you would create a manifest.txt containing this line and package it in your jar like so:

jar cfm MyApp.jar Manifest.txt com/mycompany/*.class

Java 6 also implements a parameter on the jar tool which will create/modify the entry point in an existing jar's MANIFEST.MF if you prefer.

jar cfe MyApp.jar com.mycompany.App com/mycompany/App.class
locka
@YoniGeek: You can also specify the application entry point: http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-export-jar.htm
trashgod
ohoh so many answers!! ty...
YoniGeek
I'll try to answer all yr sub questions:
YoniGeek
hye locka!! indeed, I didnt know about this manifest!
YoniGeek
where shall I place this manifest ( I mean inthe code)? ty!
YoniGeek
Just create a file anywhere called manifest.txt (the name is not important) with the Main-Class line and then when you invoke that first jar command tell it where the file is, e.g. "jar cfm c:\myworkspace\manifest.txt *.class". Alternatively you can run the second version and the jar tool will create a manifest for you inside the .jar. As trashgod says you could also use tools in Eclipse or Netbeans to do this too. Eclipse has an export wizard for the job. If you were using Maven, you could specify the main class with the maven-jar-plugin and mainClass tag.
locka
hi Locka! Well Im actually using Eclipse , so I suppose that Eclipse provides a manifest file right?
YoniGeek
I sorted it anyway!! I wasn't adding the file with the visual-material (gif-files). I think I added in the code a try-catch that check if there is any available map if there's not it would shut down....thanks anyway! yr nickname is very Scandinavian btw ^_^)
YoniGeek
A: 

what does jar file contain ? – YoK 3

It's a game

Can you give more informations ? What did you do ? What is the exact result ? – Colin

I just designed the game and I wanna send it to some ppl, they just accept JAR-files

Try to run it from the command line, and see if you get any errors (java -jar thefile.jar) – Thilo

I did! but it doesnt do anything...

What are you trying to accomplish? Piskvor

I want to send it to some other ppl..so they can "playitback" :)

YoniGeek
on emore thing , Im using Eclipse as IDE, I suppose that It automatically creates an MANIFEST.MF? right?
YoniGeek
A: 

I sorted it!!

Thanks for yr brainstorming anyway! I wasn't adding the file with the visual-material (gif-files). I think I added in the code a try-catch that check if there is any available map if there's not it'll shut down.

Gracias gente!

F/

YoniGeek