PlayN install guide… the new way

7. November 2011

 

 

Now that PlayN has been pushed into Maven Central, life and installation just got a heck of a lot easier.  Not that I appreciate their timing… couldn’t you have done this on Friday before I wrote an installer! Winking smile

 

 

I will cover two ways to create a PlayN project.

 

 

Using Eclipse to create a new PlayN project

 

 

Load Eclipse.  If you haven’t already, install the JDK and Maven m2e plugins, which are described in this thread.

 

Select File->New->Other…

 

image

 

 

 

Scroll down and select Maven Project in the Maven folder. Click Next.

 

image

 

 

Click Next again, if you don’t want to change the Workspace that is.

 

image

 

 

In the “Filter” type Playn, then select com.googlecode.playn.  Click next.

 

image

 

 

 

Now fill in your game details.  There is a small bug in Eclipse in that the Finish button will not be available until you click focus away after filling in the gameName value.  Once you fill that in, click somewhere else on the dialog and the finish button will be enabled.  Click it.

 

 

image

 

 

Your game will be created, but you might get an error like I did:  Notice the red x by the testGame-android?

 

image

 

 

If you look down in the problems section, you will see details off the error:

 

image

 

 

Fixing this is pretty straight forward.  Right click each one and select, appropriately enough… Quick Fix.  Do that for both errors.

 

image

 

 

In the following dialog, select “Permanently mark goal…” then Finish.  Another dialog will pop up, simply click OK.  You may ( I did once, and not the second time ), get another error along the lines of your project needs synchronization.  Simply Quick Fix it as well.

 

Now right click your game ( root class as in “YourGame” not “YourGame-core” ), choose Run As->Maven Install.

 

image

 

 

Sadly, I am currently getting this error still, with the Flash build being broken:

 

image

 

 

As a temp work around, open pom.xml from your root project, find Flash in the modules section and remove it.

 

image

 

 

After removing it, you get that error I mentioned earlier.  Simply right click and select Quick Fix.

 

image

 

When you do, this dialog will appear.  Select all then click Finish.

 

image

 

And you are done.  The process is actually quite a bit easier than it looks, and if it weren’t for the few incompatibilities, it would be flawless.  Regardless, it is a much nicer process than before!

 

You can now run your project, for example, right click yourproject-core and choose Run As->Java Application.  Scroll down and select your main:

 

image

 

And there is your game running in Java!

 

image

 

 

 

All told, the process takes about 3-5 minutes, a very reasonable amount of time.

 

 

 

 

Using Netbeans to create a new PlayN project

 

Now we enter the ( in my opinion ) much nicer land of using Netbeans instead of the hateful Eclipse.  As you will see in a second, this process is an absolute joy!

 

Load up Netbeans.  I am using the 7.1 beta, but other versions should be similar enough.

 

Select File… New Project:

 

image

 

 

Select Maven, then Project From Archetype, click Next.

 

image

 

 

In the New Project dialog, click Add:

 

image

 

Fill in as follows, then click OK

 

image

 

Back in the New Project Dialog, select your newly added archetype and click Next.

 

image

 

Fill the next screen in like follows.  Make sure you fill in a value for newGame and click somewhere in the dialog to make sure it takes.   Then click Finish.

 

image

 

NetBeans will churn away for a minute while it creates your project and voila!

 

image

 

 

Right click your project Core and choose Run.  In the dialog that pops up, choose your main class ( there is only one ), then Select Main Class.

 

image

 

And voila:

 

image

 

 

To fully build your project, you need to right click MyProject MetaProject and choose Build:

 

image

 

And a familiar problem arises:

 

image

 

 

Same solution too.  Under your metaproject locate pom.xml

 

image

 

 

And remove this line:

 

image

 

 

Once you edit that line and save, right click->  Build your meta project again.  This time everything should work fine.

 

 

Can you tell why I prefer NetBeans over Eclipse any day?

Programming




Son of a bit... er, I mean, GREAT NEWS EVERYONE!

7. November 2011

In one of those all time "my timing sucks" moments, Google's Fred Sauer just announced PlayN 1.0 was just added to the Maven repository, which makes the install process a few orders of magnitude easier to get up and running.

 

When I get off a tablet and back to a computer, I will document the process... it will be a short document, the process is now a heck of a lot easier.  It's a mix of ahh crap, since I just finished my installer and great news as frankly the process needed to get easier.

Programming




Actually running your PlayN game

6. November 2011

 

 

Hmm, kinda realized I missed this part in my recent PlayN installer post.  After you go ahead and create your game, it creates a new project hierarchy and… then what?  This post shows the various ways you can start your game.

 

Assuming you used my installer to install PlayN, you can run your game from the command line using the following steps.  I will assume your game’s name was “mygame” in these examples and that you installed to c:\playn.

 

 

 

Running the desktop Java app with Maven

 

 

cd playn\playn\mygame\core

..\..\..\maven\apache-maven3.0.3\bin\mvn install compile exec:java

 

 

Running the HTML target with Maven

 

cd playn\playn\mygame

..\..\maven\apache-maven3.0.3\bin\mvn package  ( wait, this takes a bit )

..\..\maven\apache-maven3.0.3\bin\mvn –Ptest-html

 

This will currently through a bunch of errors in your face since the Flash build seems to currently be broken, ignore them.  Once you run that second command, a web server Jetty will be downloaded and installed.

 

Now open a browser and go to http://localhost:8080 to see your game running in a browser.

 

When done, you can use CTRL+C in the dos window to get Jetty to stop.

 

Running the Flash target with Maven

 

You can’t, it’s currently broken, I’m looking into it and will update with details or a fix if possible.

 

Running the Android target with Maven

 

This process is a bit too involved and requires other steps ( like configuring the emulator or a physical device, which we didn’t do during the initial install.  I will cover this in detail in a later post.

 

There is a problem in that the fact Flash is broken, and before Android in the build order, your Android target will never be built!  This can easily be fixed by opening pom.xml in your game folder and remove the line <module>flash</module>.

 

Running the Java and HTML targets with Ant

 

If you have Apache ant installed, you can also use it to run Java and HTML targets. Currently you cannot run Flash or Android this way.

 

Running desktop:

cd playn\playn\mygame

ant

 

Running HTML:

cd playn\playn\mygame

ant run-html

 

Just like with Maven ( but a whole lot quicker ) it runs Jetty and you can reach your website using a browser.  However, unlike the maven install, for some reason the ant install is in a subdirectory, so your URL is http://localhost:8080/mygame.

 

 

Of course, if you are using an IDE like Eclipse or NetBeans, they can automate many of these tasks.  If you add Maven’s bin folder to your PATH variable, it will save you a ton of typing.  Of course you could also make a simply script to run your game in a much more terse syntax.

Programming




PlayN automated installer!

6. November 2011

 

 EDIT: 11/7/2011 Google has published to Maven Central, which makes this entire process obsolete.  Refer to here for new instructions.  Fortunately the new process is much nicer and faster.

PlayN is a wonder piece of technology with a horrible installation process, which is a shame as I think more people should check it out.  So I decided to do something about it, I wrote an installer!

 

I have made the process (almost ) as simple as possible.  For much more detailed process or if you encounter a problem more detailed instructions are available here.

 

 

First download the tools available here.

 

Extract the zip file to any folder ( make sure you extract though, do not run from the zip ) and run Install.cmd.

 

Now it is simply a matter of answering a couple Yes/No questions, and (optionally) point the installer at your JDK folder and telling it where you want PlayN to be installed.  Except the gotcha… read about that below before running the install!

 

 

The Gotcha

 

The only major gotcha is you *must* install the Android 3.0 SDK Platform, and you have to do it in a bit of a hurry, as the SDK install will happen in parallel to the PlayN install which is eventually going to need the Android SDK installed to continue.  I chose to do this because both installs are fairly long and the Android install *should* be completed long before it is needed.  When this screen appears, move quickly! To keep the install quick, click “deselect all” then choose Android 3.0 (API11)->SDK Platform.  You can run the Android SDK Manager again later if you want to add more features.  If for some reason the installer outpaced the Android SDK Manager, simply run the installer again.

 

 

image

 

 

 

**ALSO NOTE**

If you already have the Android SDK installed, this process *may* hijack your ANDROID_HOME environment variable.  When complete, simply change it back if you wish.

 

 

Technical Details

The installer and wizard consist of about 500 lines of Powershell script.  For the record, I have never used Powershell before, so it’s 500 lines of ugly Powershell script! Smile

 

The entire script is documented, so before running you can see exactly what it is going to do, and if it has a problem or you want to install different versions of Maven, Git or the JDK, you can change those URLs right at the top.

 

Over the course of execution, the script:

- downloads and configured the JDK [optional]

- downloads 7zip for later use ( from GameFromScratch.com )

- downloads and installs ( local ) Git

- downloads and runs the Android SDK

- Git’s PlayN from googlecode

- Downloads and installs Maven

- Runs Maven on the PlayN code

- Downloads and installed the New Game Wizard from GFS.com

- Runs the New Game Wizard [optional]

 

 

 

System requirements:

 

Java runtime.  The java sdk will be installed as part of this process, but the java runtime will not.

Powershell 2.0.  Tested on Windows 7 with Powershell 2.0, should work on Windows Server 2008 but untested. *May* work on Vista, untested.  *Should* work on Windows XP, but you will need to download and install Powershell 2.0 first.  Powershell 2.0 ships with Windows 7, and Powershell 1.0 ships with Vista and may require updating using the link above.

 

What files are created?

 

Everything is created under the PlayN installation folder you selected, except a few temp files such as the JDK installer.  These are located in your %TEMP% folder and can be deleted whenever you wanted.

 

How do I uninstall?

 

Simply delete the downloaded scripts.  If you want to erase your PlayN install, first stop adb  ( the Android debugger ).  To do so, load the task manager ( CTRL + SHIFT + ESC ), find adb.exe, right click and end process.  Now simply delete the PlayN folder you created as part of the install.

 

Anything else I need to know?

 

Yeah, the install won’t have touched your Maven or Git configurations if those are already installed, but unfortunately as part of the process we had to update the ANDROID_HOME environment variable.  So if you already have the Android SDK installed on your machine, you will need to update ANDROID_HOME to point to your installed SDK.  This can be accomplished from a command prompt by typing:

    Setx ANDROID_HOME “c:\your\androidsdk\location”

 

 

The new game wizard is installed as part of this process and can be located at [PlayN Folder]\PlayN\NewGame.cmd if you want to create a new game in the future.

 

 

If you want to install more Android SDK features after the install is complete, the Android SDK is located at PlayN\Android\SDK Manager.exe.  Yes, there is a space in the name, and no, I don’t know what the hell Google was thinking when they did that…

 

 

Running Maven after the fact is a bit of a pain in the ass.  I did not set the environment variable as part of the installed ( in case you already had Maven installed I didn’t want to break anything ) so now you have to fully resolve Maven to run it, such as c:\Playn\maven\apache-maven-3.0.3\bin\mvn.bat  [your command]  if you think that gets old in a hurry, you are correct!  The easiest answer is to add the maven Bin directory to your path, such as:

Setx PATH = “%PATH%;c:\playn\maven\apache-maven-3.0.3\bin”

Be careful with the above syntax as you don’t want to screw up your PATH variable.  Try it with a straight SET first ( no X ), then type “SET PATH” to verify it looks correct.  If you are sure it does, run it again using SETX.  At this point you can run Mvn from any directory.

 

 

 

 

IT STILL DOESN’T WORK!!!!

 

 

That’s not really shocking, there are a ton of moving pieces!  Also, I made NO checks to make sure files existed across the network or that your internet connection was up, as both of these would simply be catastrophic failures anyways.  My first suggestion is checking all the URLs at the top of the install script with your browser to make sure they are all still valid and connectivity to each site is fine.  I also have no control over if Google break their build, but if they do, let me know and I can patch the script accordingly.

 

If you have other problems, post them here, email me ( not preferred because others won’t be able to read the results ) or use the PlayN tag on StackOverflow.com and I will monitor there as well.

 

Happy PlayN!

Programming




GFS PlayN Installer–Super detailed installation instructions

6. November 2011

 

 

The Gamefromscratch PlayN installer is fairly straight forward in execution but has a few tricky points.  Also, I can’t be sure it will work 100% and you can refer to this process to see if your installation worked properly.

 

 

On occasion an environmental or Maven problem can occur during installation, or you weren’t fast enough installing the Android SDK.  If that happens, simply close the dos prompt then run the installer again.

 

 

First things first, download the GFSPlayNInstaller.  Extract this file anywhere on your computer, it will contain two files, a .CMD and at .PS1 file.  The PS1 file does all the work, but needs to be launched using the .CMD to have the proper permissions.  Do not run from within the zip, this will not work.  Throughout the install you might get a Windows firewall prompt regarding Java, this is part of the Google PlayN install process and should be granted permission.

 

 

Double click Install.cmd

 

 

A command prompt will open and you will receive a prompt to determine if your system is 32 or 64 bit; hopefully the detection is correct and you can simply click YES.

 

1

 

 

 

Now you will be prompted if you have a Java JDK installed ( the JRE is not enough! ).

 

2

 

 

 

If you do not have a JDK installed or you do not know, click No.  This will cause the JDK to be downloaded and installed automatically.  If you already have a JDK installed click Yes, and the following dialog will appear:

 

3

 

 

 

Simply navigate to the JDK directory and click OK.  Do NOT click cancel, I am not completely sure what will happen, but I doubt it’s good. Winking smile  If you clicked No earlier, you will not get this dialog.  If you clicked YES and the dialog didn’t appear, alt-tab around to see if it is there somewhere, it doesn’t always get focus.

 

 

Now you will be presented with this dialog:

 

4

 

 

 

This dialog is determining where PlayN is going to be installed.  If you simply click OK, it will be created in C:\.  Where ever you select a new folder PlayN will be created, so you do not need to create a folder just for it.  Again, don’t click Cancel…  Now the installer is going to go off and do its magic for a while….

 

5

 

 

 

Behind the scenes it is doing a number of things, downloading a zip program, grabbing Git and the Android SDK.  Even if you don’t want to develop for Android, you need the SDK installed for PlayN to work properly.  That is the next step and it is very important you do this part correctly as it was the only bit I could not automate!  You need to configure the Android SDK and you need to do it fairly quickly as the install will continue while the Android SDK install happens and eventually the install is going to depend on the SDK being installed.  Worst case scenario, run the installer again and simply close the Android SDK window when it opens.

 

 

 

As I said, this part is important, so I made a rather cryptic message box to inform you of just that!

 

 

6

 

 

 

Once you click OK, the race is on!  The Android SDK installer will be loaded and it should look like this:

 

7

 

 

 

It will take a minute or two to configure all of the various options… don’t be distracted by the installer going on in the background, keep your attention focused here!  First things first, once it’s done fetching info, click the “Deselect All” button to clear all selections.  Then you want to select Android 3 ( API11 )->SDK Platform, like this:

 

 

8

 

 

 

If everything was done correctly, the button will show “Install 1 package…”.  If you want more features, you can run the Android SDK Manager later… when you aren’t under type restraints! Winking smile

 

After you click the Install 1 package… button, you will see:

 

9

 

 

Simply click Install.

 

 

Alright, stressful bits are over, now just a matter of sitting back and letting the installer do it’s thing..

 

 

10

 

 

 

That was a screenshot of the installer doing it’s thing.  Frankly it isnt very exciting and yes, it’s a rather long process.  While that process is happening, the Android SDK Manager is chugging along and will eventually say:

 

11

 

 

Say whatever you want, it doesn’t really matter so you might as well go with Yes.  Eventually assuming success with the Maven process ( actually it runs even if there is a failure… if you see a whole bunch of failures, try running the installer again ), you will get the following prompt:

 

 

12

 

 

 

This is just another simple GFS provide script that builds your new game Maven script for you.  If you want to create a game of your own, click Yes.  If you click Yes…

 

13

 

 

The new game wizard will appear!  Simply fill in the values you want to make your game, like I have above and click Make Game!  Once you click “Make Game” a MakeGame.bat file will be created then run.  This process creates an actual game within your PlayN folder.  Unfortunately I couldn’t completely automated it and it will prompt you to continue.  When prompted ( in the dos prompt ) type Y then [Enter].  Voila, your new game is created!  If you chose C:\ for your PlayN folder, your game will be located at [C:\PlayN\PlayN\YourGame]

 

 

Finally, you will get one last prompt:

 

14

 

 

I hear there are all kinds of interesting things at that website, you should click Yes and check it out! Winking smile  If you click Yes, it will open your webbrowser ( or a new tab if already open ) and send you to GameFromScratch.com.

 

 

 

Voila, all done!  Enjoy PlayN!

 

 

If you want to create a new game at a later date, the New Game Wizard can be run again, it is located at Playn\Playn\NewGame.cmd.

 

 

If you encounter any problems, please let me know and I will do what I can.  Either use comments here, send me an email ( not preferred, because other people having the sample problem will not benefit from the results ) or I will piggyback the PlayN teams support process and request you post to StackOverflow with the PlayN tag and I will keep an eye on posts there.

General