Skip to main content
GameDev.net gamedev.net
🔒 Locked

Making executable java code??

Started by carlos100 Apr 27, 2006 at 6:35 AM 10 replies 1.6k views
Original Post
carlos100
carlos100
I'm sure this one will seem really simple to so many people on here but I don't know how to do it. I have my program all finished but it can still only be run from typing "java Game" in the command line. What do I have to do to get a nice executable file??
carlos100
carlos100
any chance of a little more detail?
Evil Steve
Evil Steve
A Jar isn't executable, it just packs everything together in one file.

The way we do it for our level editor is just create a batch file (Create a text document with the extension .bat) with these contents (We use JARs):
java -jar editor.jar

Then at least you can double click the batch file to launch the app.
OrangyTang
OrangyTang
Quote:
Original post by Evil Steve
A Jar isn't executable

They are if you've created them properly. And unlike your batch file they're cross platform.

http://java.sun.com/docs/books/tutorial/deployment/jar/

However you might find that Java Webstart would be a better distribution method and provides more functionality 'for free' than executable jars. For a start you get one-click downloading and running, and it'll auto update without any extra effort. If you've already got a jar version working then webstart is easy to add to it.

http://java.sun.com/docs/books/tutorial/deployment/webstart/index.html
Evil Steve
Evil Steve
A JAR file is just a specialized ZIP archive, how can it be execuatable? The closest that link mentions (that I can see) is:
Quote:
JAR Files as Applications
You can run JAR-packaged applications with the Java interpreter. The basic command is:
java -jar jar-file
OrangyTang
OrangyTang
Quote:
Original post by Evil Steve
A JAR file is just a specialized ZIP archive, how can it be execuatable? The closest that link mentions (that I can see) is:
Quote:
JAR Files as Applications
You can run JAR-packaged applications with the Java interpreter. The basic command is:
java -jar jar-file

By default the JRE installer creates an association between .jar files and the VM. Double clicking a jar then starts up the VM with that jar, and the manifest file you create in it specifies which class's main() method to start from.

However some tools (most notably WinRar) tend to steal this association and replace it with their own (a very broken and stupid behaviour, IMHO). If someones done that then you're out of luck. Of course if the user has fucked around with the association manually then it's their own fault.

This is one of the reasons why webstart is nicer, as .jnlp files (also registered when a user installs a JRE) don't get stolen by other applications.
Evil Steve
Evil Steve
Quote:
Original post by OrangyTang
Quote:
Original post by Evil Steve
A JAR file is just a specialized ZIP archive, how can it be execuatable? The closest that link mentions (that I can see) is:
Quote:
JAR Files as Applications
You can run JAR-packaged applications with the Java interpreter. The basic command is:
java -jar jar-file

By default the JRE installer creates an association between .jar files and the VM. Double clicking a jar then starts up the VM with that jar, and the manifest file you create in it specifies which class's main() method to start from.

However some tools (most notably WinRar) tend to steal this association and replace it with their own (a very broken and stupid behaviour, IMHO). If someones done that then you're out of luck. Of course if the user has fucked around with the association manually then it's their own fault.
Ahh, right. I never knew that, so I always tell WinRAR that it can have that extension. Thanks for clearing that up [smile]
voguemaster
voguemaster
Yes, webstart is nice, but has it's limitations and problems. For example, jar files are supposed to be signed when deployed using webstart. It's mandatory, if I recall correctly.

There are some more interesting issues that come up when you're trying to execute a JNLP file from within a browser (when your jnlp file gets downloaded to a browser in order to launch a web application).


In any case, if the jar file should just be an executable program (without any web deployment), I'd suggest using one of the many exe wrappers out there, that create an exe file for you that attempts to run the JAR file.

They usually perform checks of whether the JRE is installed, what version, etc. Basic solution unless you can settle for batch files (good under Windows only).
-----------------------------He moves in space with minimum waste and maximum joyGalactic Conflict demo reel -http://www.youtube.com/watch?v=hh8z5jdpfXY
drslinky1500
drslinky1500
A jar can be executable, on both windows and macintosh by double clicking on the jar file. This is done via the manifest file. For proof of concept you can download a demo of my program at http://www.faceinthesword.com, install it, and execute the program by double clicking a jar file. The program itself is of little interest to most people.

Feel free to unpack the executable jar labeled "jAptSchedule" and look at its directory structure and where the manifest file is located.

Here is part of Sun's tutorial on making a jar file executable.

http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html

This tutorial should show you where to place the manifest file.

In linux you will either need to enter java -jar *.jar at the command line or you can write a shell launcher.

Netbeans automatically makes jar files executable, and I believe eclipse has a plugin to do the same.

Happy Hunting

Greg
Greg Tedderhttp://www.codeugly.com/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.