Building JOGL in Eclipse

From JogampWiki
Revision as of 17:55, 10 January 2011 by Wwalker (talk | contribs) (Install EGit in Eclipse)
Jump to navigation Jump to search

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. Then double-check these things:

  • Make sure you've got a JDK installed and set up properly.
    • Make sure the JDK bin directory is on your PATH.
      • You must use a JDK bin directory, not a JRE bin directory, because Ant needs javac.exe.
    • Make sure JAVA_HOME is set to your JDK directory.
      • You must use a JDK, not a JRE, because Ant needs lib\tools.jar.
  • Delete the CLASSPATH variable if it exists.
    • Having this set with random old JARs on it is one of the leading causes of build problems.
  • Make sure ANT_HOME is set to your Ant installation directory.
  • Make sure ANT_HOME\bin is on your PATH.

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 version

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 tell Eclipse to point at your local Ant installation.

  • On the "Classpath" tab, click "Window > Preferences" and 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 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", and click the "Next" button.
  • Set "gluegen" as the project name and click the "Next" button.
  • To the "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 paths for the project so Eclipse knows which Java files to build. When we created the project, Eclipse automatically found these, but it doesn't have all the properties set like we want them.

  • Right-click the "gluegen" project and select "Properties".
  • Select "Java Build Path", then 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 folders, excluded patterns, and native library locations to the values in this table. Remove any source path 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", and click "Finish".
  • The JRE System Library should already be on this list. If it's not, click "Add Library...", select "JRE System Library", click "Next", and click "Finish".
  • Click "Add External JARs...", select ant.jar from your Ant installation's lib dir, and click "Open".
  • Click "Add External JARs...", select tools.jar from your JDK installation's lib directory, and 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. This creates the ".externalToolBuilders" directory in the glugen project.

Create the 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", and click the "Next" button.
  • Set "jogl" as the project name and click the "Next" button.
  • To the "Remove all generated resources" dialog, click "Yes".
  • Click "Finish".

Next we set up the source directories for the project.

  • Right-click the "jogl" project and select "Properties".
  • Select "Java Build Path", then click the "Source" tab.
  • Click "Allow output folders for source folders".
  • Set the default output folder to "jogl/build/jogl/classes".
  • Set the output folders, excluded patterns, and native library locations to the values in this table. Remove any source path 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", and click "Finish".
  • The JRE System Library should already be on this list. If it's not, click "Add Library...", select "JRE System Library", click "Next", and click "Finish".
  • Click "Add External JARs...", select ant.jar from your Ant installation's lib dir, and click "Open".
  • Click "Add External JARs...", select ant-junit.jar from your Ant installation's lib dir, and 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.

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

Now when you right-click projects or files in the Package Explorer, you can see the Git operations in the "Team" menu.