Building JOGL in Eclipse
Why build in Eclipse?
Building JOGL inside Eclipse lets you use the Eclipse debugger, profiler, and unit test framework. It also gives you useful editing features like auto-complete and red underlines for syntax errors.
Prerequisites
Before you can build JOGL in Eclipse, make sure you can build it from the command line.
Overview
To build JOGL in Eclipse, we'll create Eclipse projects for the gluegen and jogl projects, then add Ant builders to those projects to invoke the JOGL command-line Ant build.
Update Eclipse's Ant installation
Ant comes bundled inside Eclipse, but we need Ant 1.8 or later to build JOGL, and Eclipse 3.6 still contains Ant 1.7. So we'll tell Eclipse to point at your local Ant installation.
- On "Classpath" tab, click "Window > Preferences", select "Ant > Runtime".
- Look inside "Ant Home Entries" on the "Classpath" tab. If it shows files for Ant 1.8 or later, you don't need to change anything.
- If your Ant is older than 1.8, click the "Ant Home..." button, navigate to your Ant home directory and click "Open".
- Click the "Properties" tab, click "Add Property...", set the name to "java.home", and set the value to your JDK's "jre" directory. This is needed on Windows to get some paths in the Ant build files correct.
- Click "OK" to exit Preferences dialog.
Create the gluegen project
First we create the new gluegen project with default settings.
- Select "File > New > Project...".
- Expand "Java", click "Java Project", click the "Next" button.
- Put "gluegen" in project name, click the "Next" button.
- To "Remove all generated resources" dialog, click "Yes".
- Click "Finish". This creates the ".project" and ".classpath" files in the "gluegen" directory.
Next we set up the source directories for the project so Eclipse knows where all the Java files are. When we created the project, Eclipse automatically created these, but it doesn't have all the properties set like we need them.
- Right-click the "gluegen" project and select "Properties".
- Select "Java Build Path", click the "Source" tab.
- Click "Allow output folders for source folders". This allows the Java files in each source folder to be compiled to a different output folder, which we need to match the Ant build.
- Set the default output folder to "gluegen/build/classes".
- Set the output folder, excluded pattern, and native library location to the values in this table. Remove any source entries that are not in this list.
source | native | output | excluding |
---|---|---|---|
build/gensrc/java | gluegen/build/obj | build/classes | |
build/test/build/gensrc/classes | gluegen/build/obj | build/test/build/classes | |
src/java | gluegen/build/obj | build/classes | com/jogamp/gluegen/runtime/BufferFactoryInternal.java |
src/junit | gluegen/build/obj | build/test/build/classes | |
test/junit | gluegen/build/obj | build/test/build/classes | com/jogamp/gluegen/StructValidator.java |
Now we set up the libraries that are needed to build the project.
- Click the "Libraries" tab.
- Remove all the JARs except "gluegen/make/lib/antlr.jar" from the list.
- Click "Add Library...", select "JUnit", click "Next", select "JUnit 4", click "Finish".
- Click "Add External JARs...", select ant.jar from your Ant installation's lib dir, click "Open".
- Click "Add External JARs...", select tools.jar from your JDK installation's lib dir, click "Open".
- Click "OK" to dismiss the Properties dialog.
Finally we can set up the Ant builder. This lets Eclipse invoke our command-line Ant build.
- Right-click the "gluegen" project, select "Properties".
- Click the "Builders" tab on the left.
- Click the "New..." button, select "Ant Builder", and click "OK".
- Type "gluegen builder" as the name.
- Set the buildfile to "${workspace_loc:/gluegen/make/build.xml}" (without the quotes).
- Set the base directory to "${workspace_loc:/gluegen/make}" (without the quotes).
- Click the "Refresh" tab, check "Refresh resources upon completion", click "The project containing the selected resource".
- Click the "Targets" tab, click the "Set Targets..." button to the right of "During a "Clean".
- Uncheck "all", check "clean", click "OK".
- Click "OK" to dismiss the Edit Configuration dialog.
- Select "gluegen builder" and click the "Up" button. This makes the Ant build go before Eclipse, which is necessary because the Ant build creates some source files.
- Click "OK" to save and dismiss the Properties dialog.
Create jogl project
To create the jogl project, we do exactly what we did to create the gluegen project, but with different names and paths substituted. First we create the new jogl project with default settings.
- Select "File > New > Project...".
- Expand "Java", click "Java Project", click the "Next" button.
- Put "jogl" in project name, click the "Next" button.
- To "Remove all generated resources" dialog, click "Yes".
- Click "Finish". This creates the ".project" and ".classpath" files in the "jogl" directory.
Next we set up the source directories for the project.
- Right-click the "jogl" project and select "Properties".
- Select "Java Build Path", click the "Source" tab.
- Click "Allow output folders for source folders". This allows the Java files in each source folder to be compiled to a different output folder, which we need to match the Ant build.
- Set the default output folder to "jogl/build/jogl/classes".
- Set the output folder, excluded pattern, and native library location to the values in this table. Remove any source entries that are not in this list.
source | native | output | excluding |
---|---|---|---|
build/jogl/gensrc/classes | jogl/build/lib | build/jogl/classes | |
build/nativewindow/gensrc/classes | jogl/build/lib | build/nativewindow/classes | |
src/jogl/classes | jogl/build/lib | build/jogl/classes | com/jogamp/audio/windows/waveout/TestSpatialization.java, com/jogamp/opengl/impl/gl2/fixme/** |
src/nativewindow/classes | jogl/build/lib | build/nativewindow/classes | |
src/newt/classes | jogl/build/lib | build/newt/classes | |
src/test | jogl/build/lib | build/test/build/classes |
The jogl project depends on the gluegen project being built first, so we need to set the dependency between them.
- Click the "Projects" tab, click "Add...", check "gluegen", click "OK".
Now we set up the libraries that are needed to build the project.
- Click the "Libraries" tab.
- Remove all the JARs from the list.
- Click "Add Library...", select "JUnit", click "Next", select "JUnit 4", click "Finish"
- Click "Add External JARs...", select ant.jar from your Ant installation's lib dir, click "Open"
- Click "Add External JARs...", select ant-junit.jar from your Ant installation's lib dir, click "Open"
- Click "OK" to dismiss the Properties dialog
Finally we can set up the Ant builder.
- Right-click the "jogl" project, select "Properties".
- Click the "Builders" tab on the left.
- Click the "New..." button, select "Ant Builder", and click "OK".
- Type "jogl builder" as the name.
- Set the buildfile to "${workspace_loc:/jogl/make/build.xml}" (without the quotes).
- Set the base directory to "${workspace_loc:/jogl/make}" (without the quotes).
- Click the "Refresh" tab, check "Refresh resources upon completion", click "The project containing the selected resource".
- Click the "Targets" tab, click the "Set Targets..." button to the right of "During a "Clean".
- Uncheck "all", check "clean", click "OK".
- Click "OK" to dismiss the Edit Configuration dialog.
- Select "jogl builder" and click the "Up" button.
- Click "OK" to save and dismiss the Properties dialog.
Now we can clean and build both projects in Eclipse.
- Select "Project > Clean", click "Clean all projects" and click "OK".
Install EGit in Eclipse
After the build works we can install EGit in Eclipse. This lets you perform Git source control operations from inside Eclipse, though it doesn't yet support every feature of the command line version.
- Click "Help > Install New Software..."
- Type "http://download.eclipse.org/egit/updates" in the "Work with" box and press enter
- Check "Eclipse EGit" and "Eclipse JGit" and install
Associate Eclipse projects with git
After we install EGit, we have to tell Eclipse that gluegen and jogl are Git projects.
- Right-click "gluegen", select "Team > Share Project...", select "Git", click "Next", select the .git repository, click "Finish"
- Do the same thing for the "jogl" project