Using JOGL and SWT in Eclipse Java Projects
I recently decided that I want to learn OpenGL, so I started looking for OpenGL implementations in java. Having done a fair bit of programming with Eclipse’s Standard Widget Toolkit (SWT) and java, I ideally wanted to integrate OpenGL with SWT. I didn’t particularly want to use AWT or Swing.
After looking around, I did find that SWT now supports OpenGL through Java bindings for OpenGL (JOGL). Finding source code to test this is not easy, but there’s a convenient torus example provided on the SWT site. This was perfect for testing that I had got my setup correct.

Setting up SWT and JOGL can be annoying with Eclipse unless you know what to do. I tried the instructions that I found on the web a few times, but quickly ran into gotchas. I finally discovered the correct solution, which I’ll explain more clearly than what I found on the web.
My explanation assumes a basic familiarity with creating and running a java project in Eclipse. If you don’t know how to do this, I suggest starting with the Eclipse FAQs. My recommendation is to separate the program code from the SWT and JOGL libraries. This is particularly a good idea if you are playing with a few different SWT and JOGL projects within Eclipse.
So here we go (based on doing this for MS Windows):
- Download the SWT libraries (rather than use the library supplied with Eclipse).
- Download the JOGL libraries.
- Extract all of the .jar and .dll files in both SWT and JOGL packages to a common library folder, e.g. c:\libraries.
- In Eclipse, in your java project, open the project properties. Click on the Libraries tab, click on the Add External Jars button, go to the c:\libraries folder, and choose all of the .jar files. For the current versions of both toolkits, there should be 3 jar files (swt.jar, jogl.jar, gluegen-rt.jar). This will allow the project to compile SWT and JOGL without any errors relating to library dependencies.
- Now we want to run the application. Create a run profile as usual, but to the Arguments tab for the application in the VM arguments you need to define the location of the library using the flag -Djava.library.path=C:\Library
- The application should find the libraries correctly now, and should run!