1

I have the code on github,

https://github.com/Quillion/Game

And I would like to make it executable. jarIt.bat is the thing that makes the jar.

path C:\Program Files\Java\jdk1.7.0_04\bin;%path%

cls

javac *java

echo Main-Class: Main> manifest.txt
jar cvfm Main.jar manifest.txt *.class
java -jar Main.jar

del *.class

I can execute it on my computer using the run.bat file,

path C:\Program Files\Java\jdk1.7.0_04\bin;%path%

cls

java -jar Main.jar

but if I transfer it to another computer or Linux, I still have to use the commands to execute it. How does one create a jar file so that it can be double clicked and executed?

I am somewhat bad at the whole jar explanation, so if someone can even find a good link to share that explains everything I will be really grateful.

I have tried reading numerous explanations, but none explain how to do it properly. I know that I can accomplish this using eclipse, but I would like to learn the know how and to understand how to make one myself without any help of IDE.

Quillion
  • 6,346
  • 11
  • 60
  • 97
  • 1
    duplicate of http://stackoverflow.com/questions/5258159/how-to-make-an-executable-jar-file?rq=1 – Aaron Kurtzhals Jan 09 '13 at 18:06
  • 1
    *"I can execute it on my computer using the run.bat file, .. but if I transfer it to another computer or Linux, I still have to use the commands to execute it."* That suggests those machines do not have an association for Jar files that points to the JRE. Eclipse (or any IDE for that matter) cannot correct that. I am guessing your app. has a GUI? – Andrew Thompson Jan 09 '13 at 18:13
  • Aaron, as you see I have followed exactly what the question suggest in my code. It does not work, whenever I try to run the jar file on other machines it does not work unless if I run it from command line using java -jar command – Quillion Jan 09 '13 at 18:41

1 Answers1

1

Unfortunately, not all OS support running the jar by a double click ootb. You'd be off best by generating scripts for all environments that you need to support. You can do that with Maven and the plugin that does the scripting for you:

http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/

Btw, your jar should already run by double click in a modern windows installation! You did it quite right.

sorencito
  • 2,517
  • 20
  • 21
  • It always says invalid or corrupt jar file. Only seems like I can run it by using java -jar command. Not quite sure why it does that on every computer that is not mine. – Quillion Jan 09 '13 at 18:44
  • 1
    Does it run on your computer by a double click? – sorencito Jan 09 '13 at 18:53
  • On mine it only opens it as with winrar. I am doing something wrong definitely, but am unsure what. – Quillion Jan 09 '13 at 18:56