1

I just built a game in Java, and I want to make it so that it can be opened on any other computer without using an IDE or command line or something of the like. Basically, I want it to be like those computer games you download from the internet and start playing.

I'm sorry if this is a stupid question (or an impossible question), but english is my second language and I don't know any other way to put it. Basically, I've gotten pretty good at making video games, and I'm about done with my game, but I don't know how to make it so the game can run without an IDE. Namely, I want my little brother to be able to double click on an icon which will cause the game to start up.

Now, just approaching this logically, I'd assume whatever computer the game will be running on will need to have Java downloaded (like the JDK) or something, and I'm ok with that. I just want to be able to give someone who doesn't speak or read english a simple icon to double click on and play a game.

If this is impossible without some industry grade developers, please let me know, since I know some of the bigger games out their use their own version of a language to make the game work. I just want to know if this is possible for someone like me to do, and if so, how. Thank you for your time!

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • You want to create an executable Jar, have a look at this previous question, it will probably help. http://stackoverflow.com/questions/5258159/how-to-make-an-executable-jar-file – RobF Jun 02 '14 at 08:34
  • You should look into Jar [files](http://docs.oracle.com/javase/tutorial/deployment/jar/). They are commonly used for what you want. – Jay Rainey Jun 02 '14 at 08:34
  • On Windows? There is [Launch4j](http://launch4j.sourceforge.net/), and it even has a [Maven plugin](https://github.com/lukaszlenart/launch4j-maven-plugin). For other platforms you will need to create an Über Jar and hope that `.jar` is associated with Java. – Boris the Spider Jun 02 '14 at 08:36
  • *"Basically, I want it to be like those computer games you download from the internet and start playing."* The best way to deploy a Java desktop application is using [Java Web Start](http://stackoverflow.com/tags/java-web-start/info). And as to your now deleted question.. *"it should jump over the do/while loop, exit loop, exit programLoop(), and thus, exit main and end the program."* The EDT will still be running.. – Andrew Thompson Sep 13 '14 at 04:31
  • Thanks again Andrew, I will have to do some research on EDT – DreadHeadedDeveloper Sep 21 '14 at 03:02

3 Answers3

1

You need to build an executable jar file. A double-click on this will normally simply kick off the program, provided you have a Java runtime installed.

Note for this solution you will have to package all third party libraries into your jar, such that you have one file. But generally it's the simplest solution.

An alternative is to make the program available via Java web start. In this scenario you can click on a hyperlink, and your installed JRE will download your program and all packaged libraries, and launch that locally. The advantage is that your program updates will be identified and downloaded each time someone runs your program. The downside is that you have to host the Web Start files yourself.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
1

You're looking for a "runnable jar". When you create the jar, you use a manifest file that says what the main class is (the one with the main method). That looks like this:

So for instance, suppose your game is implemented in the package myniftygame and the class that has the main is GameMain.

The manifest file (here I'm calling it manifest.txt) would be:

Main-Class: myniftygame.GameMain

Then to build the jar, you can use the tools in your IDE or build script, or from a command line in the parent directory of your myniftygame directory:

jar cfm MyNiftyGame.jar manifest.txt myniftygame/*.class

(That slash would be a backslash on Windows.)

Then, in any modern OS with a JRE installed, double-clicking the .jar file or making it the target of a shortcut, etc., will make the runtime open the jar, see the manifest, and call the myniftygame.GameMain.main method.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
1

Create a runnable jar or better still use executable wrappers like Launch4j. Executable wrappers do provide features like standard windows installers and will prompt you to install JDK/JRE if not already installed or you can even bundle a JRE.

Dhrubajyoti Gogoi
  • 1,265
  • 10
  • 18