New to Slick2D, help getting started

Ok so I don’t know who saw my other post but I’m trying to convert my game to Slick2D but I am having a bit of trouble getting started. Everything compiles correctly but when I try and run just an empty application with Slick2D i get “Exception in thread “main” java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path” what all do i have to do to use Slick? I added slick.jar, lwjgl.jar, and ibxm.jar to my project. Apparently I’m missing another step…

Also just out of curiousity what is ibxm.jar? I just added it according to some tutorial.

That is a common error people new to slick/lwjgl get.

Remember LWJGL has two parts, a java part and a native code part.

so

  1. you must add the java part (lwjgl.jar), it appears you have done this.

  2. the error relates to the lwjgl not finding the native files (*.dll on windows, *.so on linux, etc). You must either set your IDE to point to the folder containing them or set a VM argument -Djava.library.path=“folder contain natives” which points to the native files. This will allow LWJGL to find the native files.

ibxm.jar is a library which you can use with Slick2D to play MOD/XM sound files, its optional so if you not using MOD or XM files you don’t need it.

ok cool so i need to add slick.jar and lwjgl.jar as well as add the natives to the VM.

another question. say I want to distribute my game, how is that handled? do i include all three natives (ie. windows, mac, linux)? package it all into a jar?

This is different depending on the type of deployment method you choose, for Java Web Start and Java Applets you will put the natives into jars (one jar for each platform, all the natives for each platform will be in one jar).

For deployment as an executable jar or batch script the natives will be in folders (not in jars) to which you simply link to on the classpath with the -Djava.library.path=“path” parameter.

ok still having problems. I extracted the files from natives-win32.jar and got lwjgl.dll, jinput-dx8.dll, jinput-raw.dll, and openal32.dll. I put all of these in a folder. From the command line I tried to set the VM argument like you said but it keeps telling me that it can’t find the main class. What am i doing wrong? can you tell me exactly what i have to type in the command line?

i was doing: java -Djava.library.path=“folder location”

which IDE are you using?

put the files somewhere like the natives inside c:\lwjgl

then you’d use java -Djava.library.path=“c:\lwjgl”

I’m using JCreator and whenever i type in java -Djava.library.path=“c:\lwjgl” the command outputs the same help stuff as if i just typed java.

can’t really help with JCreator since I use Eclipse.

What you can do is have a look here http://lwjgl.org/installation.php
Its a small guide on how to setup lwjgl with JCreator, not sure how up to date the guide is though.

I still can’t get it to work. This doesn’t make any sense. I wonder if there is a problem with me running Java 32 bit even though my machine is 64 bit. I guess I’ll try using eclipse and see if that changes anything

just out of curiousity can 64 bit systems use the 32 bit natives? I downloaded lwjgl and they have both 32 bit and 64 bit natives included. granted this has not solved my problem but again assuming that i get this working how does that play into distribution? just include both sets of natives?

edit: upon using NetBeans it works flawlessly. Also I used the 32 bit .dlls and it ran on my machine so I guess they do work.

However, what if the user has the 64 bit JRE. Would they too be able to use the 32 bit .dlls?

haha sorry for being all over the board with the questions. At least i can start coding using netbeans. hopefully i’ll leave you alone soon kapta :slight_smile:

n bit JRE => n bit libs

for an executable jar how do you set the -Djava.library.path=“path” ??
do i just put this path in the class-path: in the manifest file?

sorry I tried searching the web and can’t find much on this…

thanks riven. so for distribution i should put the 64 bit and 32 bit dlls in the windows natives file? will the JRE automatically pick the correct ones?

You can even set the parameter within your app:

System.setProperty("java.library.path", "...")

Naturally, you cannot load libs from within the JAR, as the OS has to load them as files.

where would this line of code go in my app?

Before you do anything LWJGL / Slick2D related.

A safe place would be the first line of your main method.

yup as Riven mentioned above, you can use the setProperty stuff to set the path to the natives folder outside your executable jar.

Here is an example of how to use batch scripts to distribute your app.

OK, this is probably a bit off-topic for the original post, but …

I’ve always been impressed by the way that the JNA library extracts and runs its native code directly from a JAR. Alright, it’s extracting them to the temp directory so that the OS can load them as a file, but this makes setup and distribution so much simpler - just put the JAR on the classpath. I don’t think it’s a solution that would work for everything, but would love to see this principle used more.

I do think that it would work for ‘everything’, and it’s not hard to code that functionality.

Writing it in the (system) temp-file wouldn’t be my first choice, as it can be overwritten accidently or even intentionally. It’s better to extract it where you have exclusive privileges.

With JNA it gets written to the temp file system purely for that one loading, and is deleted on VM exit. Personally, I like that better. But, anything that worked from the classpath would be an improvement.

The one case I think this might not work is for libraries where setting java.library.path doesn’t work either. Eg. JMF (yuck!) has multiple libs that link off each other. The first is loaded from the Java library path, but the links are loaded from the system library path.