So after running through my earlier Getting Started with PlayN tutorial, I never actually tried running the HTML5 target and today I tried it.
First task, as a non Java developer was figuring out just how the hell to actually run it. All of the Google examples seem to use ANT so I went that route. Unfortunately I didn’t have Ant installed on my machine, which isn’t quite as simple as double clicking an installer EXE.
First head on over to Ant’s webpage and download the zip.
Extract the zip file to some folder, I put it in my C route so the path was C:\apache-ant-1.8.2\
Now you need to add a few environment variables. ( Right click Computer->Properties->Advanced System Settings->Environment Variables )
First you need to add the ant bin directory ( c:\apache-ant-1.8.2\bin in my case ) to your already existing PATH variable. Just add a semicolon to the end append your ant path.
Next you need to make sure JAVA_HOME is defined and points to your java SDK root folder.
Finally you need to add ANT_HOME, which points to your ant directory ( C:\apache-ant-1.8.2 ) with no trailing slash.
Now open a new command prompt ( not an existing one, as the settings wont take ) and type ant. If you are configured correctly you will get an error like:
If you get that error, you are off to the races! Anything else and you probably have a problem somewhere in your install.
Now in the command prompt go to the directory you created your game to. In my case its c:\users\Mike\workspace\MyGame\. Once there type ant run-html, and if you are anything like me, you are about to get an error message :
Unable to resolve artifact: Missing:
So why did this error occur? Because Eclipse mucked up the Maven install earlier. Fortunately now that you have ant installed, the fix is quite easy. In a command prompt, change to the folder you installed Playn to, in my case it was C:\Playn\. Once there type ant install. After doing its thing, your maven repository should now be properly configured. Now go back to your game install folder and type ant run-html again. Now with everything properly configured, ant will start up a local web server and host your game. When done, it should look something like this:
At this point, open up your web browser and go to http://localhost:8080/YourGameName
And voila, your game running in a browser:
Now, dropping to the command line every time you want to run your application is annoying, very annoying. So how exactly do we run our HTML ( and other ) builds within Eclipse?
Open up Eclipse, select the Window menu –> Show View –> Ant
The Ant window will now be visible like this:
Click the +Ant icon ( far left ). A window will pop up like this:
Select your game ( not the sub projects ) in my case “MyGame”, expand it and select Build.XML and then click OK.
Now your game will show up in the Ant view. Expand it and you will be able to see your various Ant targets:
Right click run-html, select Run As->Ant Build. Now just like before, open a web browser and navigate to http://localhost:8080/YourGameName/
Voila, your game run from inside Eclipse.