JOGL example with compile and execute instructions (jsr 231 1.1.1, Fall 2008)

We’ll assume that you are running Eclipse as your IDE but will use Ant to run the program. Ant works with other IDEs and the command line as well. We have Eclipse and Ant installed in our lab but the software is free so you may want to install it on your machine as well. Here is a handout on creating a project with Eclipse and using Ant to compile it. A small non-jogl java file, MatchGame.java, was used in that handout. If you would like to download Eclipse you might try the version for Java Developers. Eclipse documentation is online but if you  may also use the built in help.

1) Within Eclipse, make a new Java project (JOGLDraw) with separate folders for sources and class files.
The quickest way would be to download and decompress the zip file. Then within Eclipse, use the File -> New -> Java Project option and select the "create project from existing sources" option as shown to the right. The source folder "src" should contain the package "example485" which contains the java source files. Click finish to create the project. [ If you are using Eclipse for the first time, dismiss the "Welcome Tab" by clicking on its close box. You can retrieve the "Welcome" again through the Help menu.]

To make the small red "x" boxes (indicating problems) go away, Eclipse needs to know where you have placed the JOGL libraries. Right-click your project's "Referenced Libraries" and use the "Build Path" option to configure the build path. You want to "Add external jars" to add in the gluegen-rt.jar and jogl.jar files as shown below. These files from the  JSR-231 1.1.1 (May 2008) release should already have been loaded on your machine.
   After setting up your project in Eclipse, the Package Explorer view should reveal a file structure as shown below. The build script depends upon files being correctly named and placed within the correct folders.

project file structure
creating new project

2) To run in the lab, execute the "run2102" target of the Ant build file.  The build file can be opened by double-clicking on build.xml within the Package Explorer view. (see handout for details on how to run Ant targets).

What if you get a "can't find compiler error"? Under the Eclipse "Window" menu, select "Preferences ...", look at the Java section and bring up the "Installed JREs". Make sure you have selected a Java JDK (with the tools like the compiler) rather than just a JRE (run time environment for nondevelopers). Use the search button to find an appropriate jdk on your system.

3) Modify the build.xml file if needed. (to develop and run on your computer)
3a) To run in another environment, make sure the jogl files(JSR-231 1.1.1 (May 2008) release) are on your system and note where the jar and native (dll) files are stored.
3b) Edit the build.xml file to set the values for myJoglLibs and myJoglNative to those directories.
3c) Execute the "myRun" target. You should be able to work at home using "myRun" and in the lab using "run2102".

To allow Eclipse to find the files while you edit code, edit your project's properties, "Java Build Path", to specify where the jogl jar files are. Use "Add external jar" to add jogl.jar and gluegen-rt.jar. For future assignments, make sure to update the build file property "mainClass" if needed.

Submit your build.xml file with the rest of your source code. Test the target "run2102" to confirm it works in our lab. The TA will use the build file and target "run2102" to check your lab.

Check the online Jogl Users Guide for more indepth discussion of jogl. Since jogl provides OpenGL bindings, consult the OpenGL documentation such as the OpenGL Prog. Guide and OpenGL Ref. Manual for OpenGL details. To ease some aspects of program development (like defining text and various shapes) jogl includes a subset of GLUT . These notes were originally put together to assist students in CS485F08. To obtain the specific distribution used for that class, download the  JSR-231 1.1.1 (May 2008) release.

The Jogl distribution includes jar files as well as native libraries. In general, there is much flexibility about where these files can be placed (it is discouraged to place the files in the extensions directory of the JRE.) To compile and run your code you just need to specify where things are. This can get tedious and prone to typoes so these instructions show how run them with an Ant script  (Ant is commonly used in Java development to automate builds. It comes bundled with Eclipse).


Return to CS485F08 assignments