Setting up SlickSet in NetBeans
By Aaron Lindsay
This article is here to help you get something up and running to work with SlickSet in the NetBeans Java IDE. If you are unfamiliar with SlickSet, more information can be found in the What is Slickset? thread at the official SlickSet forums.
Now, some may have trouble starting a game in SlickSet or just wanting to test out and compile one of the SlickSet demos. In any case, you’ll need to follow the steps outlined in this article to create a new project.
1. Obtain a SlickSet release
First things first, you’ll need to get SlickSet before you can do anything. To start, download the Full Package. This package contains everything you need to get a SlickSet game going. At this time it is also recommended that you download the Javadocs to be used inside of the NetBeans IDE; it is very useful to have them on hand and view the details about the library as you use it. Make sure you grab the offline SlickSet Javadoc, and also get the Slick Javadoc (SlickSet is used in conjunction with Slick) in the “javadoc” folder from the Slick main distribution.
2. Group Slick(Set) as a library
If you plan on using the (extremely useful) Javadoc features of NetBeans, you’ll need to group Slick and SlickSet as a library. Even if you don’t care for that, grouping SlickSet as a library helps you to instantly add the JARs to your project without you having to search around for them. Doing this step is optional, but recommended for everyone.
Now, whether you wish to group them together or separately is entirely up to you; it depends on how you want it organized and whether you ever use Slick on its own. To start, go to the menu Tools > Library Manager (just called Libraries in NetBeans 6.0) to open up the Library Manager. Click the New Library... button, and name the library whatever you wish, such as “SlickSet”. Once it’s created, click Add JAR/Folder... to add the SlickSet JARs to the classpath. If you’re keeping Slick and SlickSet apart, SlickSet only consists of slicksetx.x.jar, while Slick needs slick.jar, lwjgl.jar, jogg-x.x.x.jar, jorbis-x.x.x, and jinput.jar (Note that version numbers change so the filenames will not actually have ‘x’s in them, but their actual version number). If you’re putting them all in one library, simply add all the JARs to the same library. That done, go to the Javadoc tab and use the Add ZIP/Folder... button to add the Javadocs you downloaded in step 1. Again, if you’re keeping the libraries separate, add the Slick Javadoc to the Slick library and the SlickSet Javadoc to the SlickSet library; otherwise put both Javadocs in with the one library. Now you can easily add the libraries to any project without hassle.
Organize your libraries as you see fit.
3. Start a new project
This is the simplest of tasks, just start a new Java application project from the toolbar or the menu File > New Project... and name it whatever you desire.
4. Add the libraries
Assuming that you followed step 2, you can easily add the libraries by right-clicking on the Libraries node under your project in the project explorer, and select Add Library. In the dialog that pops up, select the libraries you created earlier and hit Add Library; you can now use the Slick (org.newdawn.slick) and SlickSet (com.slickset) libraries in your game!
You can easily add the SlickSet library to any project in just a few clicks!
If you didn’t follow the advice in step 2, it’s a similar method to add the libraries to your project: by right-clicking the Libraries node under your project in the project explorer and selecting Add JAR/Folder, you can then locate and add the JARs listed in step 2, which should all be together in one folder in the full SlickSet package. The libraries tip just saves you the trouble of searching for them, and also adds integrated support for viewing the Javadoc information from inside the IDE.
5. Copy the native libraries
Yes, there’s a little bit more, and this tends to be the tricky part to figure out on your own. You should have found four .dll files in the SlickSet package, and this is where they’re used. If you’re on Windows, this is a cakewalk; simply copy the native libraries that can be found in the SlickSet package (OpenAL32.dll, lwjgl.dll, jinput-raw.dll, and jinput-dx8.dll) to the root of your project folder, which should be named after your project.
For those on Linux or Mac, you’ll need to dig into the Slick distribution and open up the lib/natives-linux.jar or lib/natives-mac.jar (depending on your operating system) in an application that supports ZIP archives and extract their contents, placing them in the root of your project folder, as explained above. After that, right-click on your project's name in the project explorer and select Properties. In the window that opens, select the Run tree list item and enter "-Djava.library.path=." in the VM Options text field.
NOTE: If you get errors about version mismatches, see the troubleshooting section at the end of the article for a solution.
6. Copy existing source files (optional)
In the case that you’re testing out one of the provided SlickSet demos, you’ll need to obtain the source of them from either the demos page or the SVN repository (http://svn.stencylworks.com/slickset/ with the username/password combination of slickset/slickset). Place the downloaded source into your new project’s src/ folder. Make sure you do this correctly, so that the source is in src/ like its classpath; in the case of the demos, this means that /src/com exists. Also take the res/ folder that is required and provided by some demos and place it not inside src/ but alongside it, inside your root project folder.
Once the source files are straightened out and in the right place, hit F6 in NetBeans to run it (you’ll be prompted for a Main class, there should only be one choice, so select it and continue). If you encounter any problems, see the troubleshooting section below.
So, that's it, you're all set up. It's not that complicated, you just need to get the libraries straight at first and then it's easy enough to set up projects afterward. As for tutorials to use it, there are none available at the moment, so just have fun playing around with some of the demos and learn from Jon's examples. Soon enough other projects/demos will be released by members of the team, and tutorials are on their way in the near future. Feel free to stop by the #stencyl IRC channel on irc.initialized.org for any help or just friendly discussion. Enjoy!
There are a couple common problems that may be encountered, and the common solutions can be found here.
I get “no main class found” when trying to compile a demo. In this case, NetBeans hasn’t yet realized that you copied new files into the src/ directory. Give it a friendly push by expanding the Source Packages node under your project in the project manager. It should find everything quickly, hit F6 again to run it, and it should offer the main class up.
The program compiles fine, but I get a “java.lang.UnsatisfiedLinkError” when it runs. This problem occurs when the program can’t find the native libraries. Ensure that you’ve copied the right files to the root of your project folder, as described in step 5. In some cases you'll need to give the -Djava.library.path=. flag to the VM (this doesn't seem to be an issue on Windows) as described at the end of the second paragraph in step 5.
It’s telling me “Resource not found: res/somefile.png” when I run a demo. As the error says, it can’t find the resource it’s looking for. Ensure that you’ve copied all files in the res/ directory of the demo if there was one provided, and that the res/ folder is located in the root of your project folder. If it still continues to complain, ensure that the file actually exists, and report any bugs like missing resource files to the developer. Keep in mind that SVN source can easily be unstable and liable to problems like this.
My program compiles, but when it runs it tells me “main version mismatch in jar file.” You have mismatched versions between a JAR and native library. If the native libraries that came with SlickSet or Slick (for non-Windows libraries) are mismatched, please bring the issue up at the SlickSet forums. To fix it for yourself, go download the latest LWJGL release and replace any JARs and libraries with those from this newest download.