Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is it possible to turn a Java application into a standalone package that runs "out of the box"? The end user should not be required to install any Java JRE, nor should the installer contain a JRE and install it for the user.

The final distribution should contain a native executable (hopefully one for each of Windows, Mac and Linux) along with the regular data files and any extra JARs if needed. I'm not looking for a "one file" solution specifically -- I'd actually like data files to be unobfuscated.

How can this be done?

share|improve this question
add comment

2 Answers 2

up vote 8 down vote accepted

The main point is that the end user should not be required to install any Java JRE, nor should the installer contain a JRE and install it for the user

You can use Java source/bytecode to machine code compilers. There are Excelsior JET for Windows and Linux (requires license) and GNU Compiler for Java which is old.

If it's ok to contain Java with your game without installing it, then you can probably package Java Runtime with your game and use a start script to set JAVA_HOME to your JRT location prior to launching the game.

EDIT: (comment response) Using the second option, you will still need different builds for different platforms using the appropriate Java runtime for that platform.

share|improve this answer
3  
If your game is non-commercial, you can get a free Excelsior JET license. –  Dmitry Leskov May 12 '13 at 6:53
    
The second option sounds good, but if I package my Windows JRE, is it crossplatform? Similarly with Excelsior, would I need to run such compilers on the three different OSes? –  leokhorn May 15 '13 at 7:42
1  
You would need to bundle that platforms JRE with each release, but essentially it will remain cross platforms. –  Derek May 15 '13 at 19:26
1  
@leokhorn At some point, there has to be native code. Either you have to compile to native code, or you have to run on a native VM. There is no plan C. –  Adrian May 16 '13 at 19:28
add comment

For Mac, see the Oracle documentation for packaging a Java app for Mac. They've set up Java 7 so that you can bundle the runtime into an application bundle containing your jar files (.app is a folder treated as executable really), which is required for distribution on the Mac App Store. Basically, the .app bundle does mostly the same as what Eren's JAVA_HOME answer suggests, but is packaged as a "native" Mac app.

For distributing without the Mac App Store, you can get away with not signing the app, telling your Mountain Lion users that they can get around Gatekeeper by right-clicking (or ctrl+click) on your app and clicking on "Open" when they first open the app. This will still warn them that the app is not signed, but it will allow them to open it anyway, and then allow them to double click on the app for subsequent opens.

(side note: you could also get away with Linux-style marking of shell scripts as executable and then construct a .app bundle around that. NetBeans does this on Mac and Linux, though without a bundled JRE/JDK)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.