Setting up LWJGL with Eclipse

This tutorial will run you through the steps you'll need to get LWJGL setup with the Eclipse IDE.

This can be tricky if you are not familiar with the IDE because unlike most Java libraries LWJGL has two parts, a Java part (lwjgl.jar) and a native code part (*.dll files for Windows, *.so files for linux and *.dylib/*.jnilib for Mac). Both parts must be set in order to use the library.

Firstly download LWJGL from its sites download page. You'll just want the standard download bundle (lwjgl-x.x.zip), you can ignore the source, docs and applet bundles for now.

Extract the contents of the bundle to somewhere on your computer, it does not have to be in any specific location. Do not put it in the Java installation directory.

Next start up Eclipse and create a new project.

Then right click the project and choose properties.

Next select 'Java Build Path' and then the 'Libraries' tab.

Add lwjgl.jar as an external jar by clicking the 'Add External Jars..." button.

If you intend to use OpenGL's GLU class you should also add lwjgl_util.jar. If you are using the Slick2D library then you should also add slick.jar here.

Finally we need to setup the native component of LWJGL. This is done by clicking the little arrow next to the lwjgl.jar file to show the drop down list. Double click 'Native library location' and select the folder that contains the native files for your operating system and clicking OK. These are located in the natives folder include in the LWJGL download bundle (e.g. On Windows you'd point to the natives\windows folder which contains the *.dll files, On Mac you'd point to the natives/macosx folder and on Linux you'd point to the natives/linux folder).

That's it, you now have LWJGL setup with Eclipse and can begin coding.

Comments

so, I downloaded the lwjgl file, but when I tried to enter the location of native libraries,I just realized that there is no "natives" folder. Only a "native" folder that does not have any .dll files in it. What should I do?

Anonymous Ninja
Wed, 09/09/2015 - 14:49

So I went to the online site and downloaded the LWJGL zip (it's at version 2.8.5 at this point.) But that zip file didn't have any .jar files! What's going on here? Did they upload a bad version or something?

Anonymous Ninja
Sun, 02/03/2013 - 22:43

Thanks, mate, you just saved my life :)

Anonymous Ninja
Sun, 07/08/2012 - 05:49

absolute hero saved my life!

Anonymous Ninja
Wed, 10/10/2012 - 09:44

Hi,

I *JUST* got Eclipse successfully installed & am trying to get it to point to the correct location, so that I can do game development with Eclipse & LWJGL. But only my Eclipse install has gone correctly. I extracted the LWJGL files to C:\LWJGL as it's destination, but I do not see any folders named 'natives'. Additionaly, I also downloaded the 32-bit JDK (don't know how to install that). The JRE was an executable & did it's own thing nicely. So any advice you can give here is really helpful!

Anonymous Ninja
Wed, 06/06/2012 - 21:12

did you grab the right lwjgl package? at the time of this post the latest version is lwjgl 2.8.4, make sure you grab this file

admin
Wed, 06/06/2012 - 21:34

I am working on a game with LWJGL, Slick and SoundSystem (by paulscode @ www.paulscode.com) and I have done this setup with eclipse tonnes of times and everything works but when I go File > Export (opens a dialog) Java > Runnable Jar or something like that then export the game to a jar. When I run the game it comes up with this:

C:\Users\17082>java -jar D:\17082\Desktop\Game.jar
Starting main thread...

Starting up SoundSystem...
Initializing OpenAL
(The lwjgl binding of OpenAL. For more information, see http://www.lwjgl.or
g)
Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: no lwjgl in java.
library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:82)
at org.lwjgl.Sys.(Sys.java:99)
at org.lwjgl.openal.AL.(AL.java:59)
at paulscode.sound.LibraryOpenAL.init(LibraryOpenAL.java:73)
at paulscode.sound.SoundSystem.CommandNewLibrary(SoundSystem.java:1841)
at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2461)
at paulscode.sound.CommandThread.run(CommandThread.java:100)
ERROR MESSAGE:
SoundSystem did not load after 30 seconds.
ERROR MESSAGE:
SoundSystem did not load after 30 seconds.
ERROR MESSAGE:
SoundSystem did not load after 30 seconds.
Cleaning up!
Exception in thread "Main Thread" java.lang.NoClassDefFoundError: Could not init
ialize class org.lwjgl.opengl.Display
at src.Game.cleanup(Game.java:205)
at src.Game.run(Game.java:67)
at java.lang.Thread.run(Unknown Source)

I tried running it with this command: java -jar [jarfile] -Djava.library.path=[natives path]
but nothing works! I have been looking at like everywebsite trying out the solutions but
I must be doing something wrong please help!!!

Anonymous Ninja
Sat, 09/17/2011 - 15:14

The above error just means you haven't setup the native component of LWJGL properly, see the end part of the above tutorial and try again.

admin
Sat, 09/17/2011 - 18:24

Helo, I have the same error when I try to launch my jar after compiled it with Eclipse.
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/opengl/Display
But on Eclipse the application launch properly. (and I made all what is said in the tutorial about the .dll)

Anonymous Ninja
Wed, 07/25/2012 - 15:52

Solved my problem with a command line launching code.

Anonymous Ninja
Wed, 07/25/2012 - 16:19

Where exactly would I find these "native files," specifically for Mac OS X?

Anonymous Ninja
Wed, 04/20/2011 - 16:41

once you download the LWJGL download bundle, you'll find them in the folder natives/macosx

admin
Wed, 04/20/2011 - 19:55

How can you add the native files for multiple OSs to the same project, so that it works on both os x and windows, for example

Anonymous Ninja
Thu, 12/01/2011 - 18:49

You just include them all, LWJGL will automatically detect which OS its on and load only the required natives.

admin
Thu, 12/01/2011 - 20:34