Here is a quick an easy tutorial for making a Java Webstart version of a Slick based game with the help of Eclipse. A more thorough wiki on the subject is available here, and an older and I think slightly out of date document is here.
Create a Jar file
First, right-click on your project and select “Export…”
Second, select a Java – Jar File.
Third, choose “Export generated classes and resources”, and put checkmarks next to any folders in your project which contain either source files or resources (images, sounds, etc). Fill in a name for the exported jar file, and hit Next.
Fourth, (optional) select the “Save description…” box and put in a place to save your export properties. This will allow you to easily export your jar file again later when you want to update your webstart.
Create a JNLP file
Fifth, we create a .jnlp file. This provides the meta information about your project like where it is located on the web, and what other libraries it requires. In Eclipse, choose to create a new File, and name it yourproject.jnlp.
Sixth, fill in the file with this template (borrowed from the Slick wiki)
<?xml version="1.0" encoding="utf-8"?>
<jnlp
spec="1.0+"
codebase="http://www.mydomain.com/games"
href="mygame.jnlp">
<information>
<title>My Game</title>
<vendor>My Vendor Name</vendor>
<homepage href="http://www.mydomain.com"/>
<description>My Game</description>
<description kind="short">My Game</description>
<icon href="icon.gif"/>
</information>
<resources>
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+" max-heap-size="128m"/>
<jar href="mygame.jar"/>
<extension href="http://slick.cokeandcode.com/demos/slick.jnlp" version="0.4"/>
</resources>
<application-desc main-class="MyMainStartupClass"/>
</jnlp>
Seventh, replace the generic info with the specifics of your project. In particular, you must specify:
- codebase: the URL for the directory where your .jnlp and .jar files will eventually be stored
- href: the name of the .jnlp file you just created
The title and homepage you can fill in as you wish. In the <resources> section you can specify if your code requires a specific version of Java. The second line <jar href=”mygame.jar”/>, should be replaced with the name of the .jar file you made way back in step 3. Finally, the <application-desc main-class=”MyMainStartupClass”/> should specify the class in your project with the “main” method.
Send it to the web
You have now created the two files you need. All that remains is to upload the .jar and .jnlp files to your webserver. Be sure that you place the files into the same exact directory that you specified in the .jnlp file!
Tenth (sorry we skipped a few numbers), open up the URL of your .jnlp file and play your game!
What if it doesn’t work?!
A few things can go wrong. Most comonly, you don’t set a path or file name right for either the .jnlp, .jar, or main class. Double check those first. Also, keep in mind that you cannot just change a local version of the .jnlp file on your desktop and double click it — you must upload the changed file to the server to make the changes have any effect.
If going to the .jnlp URL just results in showing you the text inside of the file, then you need to tweak some settings on your web server so it understands that web clients don’t want to read XML, they want to play your game! A couple of solutions to this are available here. Most likely you can fix the problem by adding these lines to a .htaccess file in the directory with your .jnlp:
AddType application/x-java-jnlp-file .jnlp
Hope that helps!