Setting up a JogAmp project in your favorite IDE: Difference between revisions

From JogampWiki
Jump to navigation Jump to search
(Added Eclipse screenshots)
(Added command-line compile and run instructions; simplified and streamlined explanations; moved explicit mention of JOCL, JOAL, and GlueGen to beginning)
Line 1: Line 1:
__TOC__
__TOC__


It's very simple to set up a project of your favorite IDE to use a JogAmp library. These instructions assume you've already created a new project in the IDE.
These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.


= Download a JogAmp project =
= Download a JogAmp library =


If you haven't done so already, download and extract for example JOGL as described at [[Downloading_and_installing_JOGL]].
If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at [[Downloading and installing JOGL]].


To be able to use a JogAmp library you will have to add the jar files to the classpath and the native files to the library path of your projects run configuration.  
To use a JogAmp library you'll have to add its JAR files to the Java classpath and its native libraries to the Java library path. Each IDE has a slightly different way to do this, as we show below.
Please note that all projects depend on the GlueGen runtime libraries which are for convenience reasons included in every JogAmp project but only required once in the classpath/library path of your application.
 
Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.


= Eclipse IDE =
= Eclipse IDE =
Line 16: Line 17:


* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.
* Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.
* Click the "New..." button, type "JOAL", "JOCL", "JOGL" or "GlueGen RT" for the library name, and click "OK".
* Click the "New..." button, type "JOGL" for the library name, and click "OK".
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]
[[File:Eclipse_setup_01_create_user_library.png|300px|thumb|none|Create user library]]
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select them, then click "Open".
* Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select them, then click "Open".
Line 23: Line 24:
* Click "OK" to exit Preferences dialog.
* Click "OK" to exit Preferences dialog.


=== Add JOGL to your project's dependencies ===
=== Add the user library to your project's dependencies ===


* Right-click your project in the Package Explorer and clock "Properties".
* Right-click your project in the Package Explorer and clock "Properties".
Line 35: Line 36:


= IntelliJ IDEA =
= IntelliJ IDEA =
=== Add JOGL dependency to project ===
=== Add a library dependency to your project ===


* Click "File > Project Structure".
* Click "File > Project Structure".
* Select "Modules" on the left, then click the "Dependencies" tab on the right.
* Select "Modules" on the left, then click the "Dependencies" tab on the right.
* Click the "Add..." button, then click "Library...".[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]
* Click the "Add..." button, then click "Library...".[[File:IntelliJ_setup_01_add_library.png|300px|thumb|none|Add library]]
* Type "JOAL", "JOCL", "JOGL" or "GlueGen RT" as the library name.
* Type "JOGL" as the library name.
* Click "Attach JAR Directories...", navigate to the directory where you extracted the JARs and click "OK".
* Click "Attach JAR Directories...", navigate to the directory where you extracted the JARs and click "OK".
* Click "OK" to dismiss the Configure Library dialog.[[File:IntelliJ_setup_02_configure_library.png|300px|thumb|none|Configure library]]
* Click "OK" to dismiss the Configure Library dialog.[[File:IntelliJ_setup_02_configure_library.png|300px|thumb|none|Configure library]]
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this.[[File:IntelliJ_setup_03_external_library.png|300px|thumb|none|External libraries]]
* Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this.[[File:IntelliJ_setup_03_external_library.png|300px|thumb|none|External libraries]]
=== Add the native libraries to the run configuration ===
* Click "Run > Edit Configurations".
* Click "Run > Edit Configurations".
* Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box.[[File:IntelliJ_setup_04_run_configuration.png|300px|thumb|none|Edit run configuration]]
* Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Parameters" box.[[File:IntelliJ_setup_04_run_configuration.png|300px|thumb|none|Edit run configuration]]
Line 51: Line 53:


= NetBeans IDE =  
= NetBeans IDE =  
=== Create a JOGL library dependency ===
=== Create a library and add it to your project ===


* Right-click your project and click "Properties".
* Right-click your project and click "Properties".
* Select "Libraries" on the left and click "Add Library...".
* Select "Libraries" on the left and click "Add Library...".
* Click the "Create" button, then type "JOAL", "JOCL", "JOGL" or "GlueGen RT" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]
* Click the "Create" button, then type "JOGL" for the library name and click "OK".[[File:NetBeans_setup_01_create_library.png|300px|thumb|none|Create library]]
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".
* Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".
* Click "OK" to dismiss the Customize Library dialog.
* Click "OK" to dismiss the Customize Library dialog.
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]
* Click "Add Library" to dismiss the Add Library dialog.[[File:NetBeans_setup_02_add_library.png|300px|thumb|none|Add library]]
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]
* Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.[[File:NetBeans_setup_03_libraries_in_project.png|300px|thumb|none|Libraries in project]]
=== Add the native libraries to the run configuration ===
* Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.
* Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.
* Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]
* Type <tt>-Djava.library.path=your/path/to/native/library/files</tt> in the "VM Options" box.[[File:NetBeans_setup_04_native_library_path.png|300px|thumb|none|Native library path]]
Line 66: Line 69:
That's it! You can now use the library in your project.
That's it! You can now use the library in your project.


= Vi =
= vi and other text editors =
=== Open a shell of your choice ===
=== Create your project with the editor of your choice ===
$vi <return>
* For example, to open vi, simply type <tt>vi</tt> and press <return>.
* Type all your code, then save it.
 
=== Compile and run your project from the command line ===
* We assume your JOGL JAR files are in a directory called <tt>jar</tt>, and your JOGL native library files are in a directory called <tt>lib</tt>.
* First compile your program. We assume all your code is in a single file called <tt>name/someone/MyProject.java</tt>.
** Windows: Type <tt>javac -classpath "jar\gluegen-rt.jar;jar\nativewindow.all.jar;jar\jogl.all.jar;jar\newt.all.jar" name\someone\MyProject.java</tt>
** Linux/MacOS X: Type <tt>javac -classpath "jar/gluegen-rt.jar:jar/nativewindow.all.jar:jar/jogl.all.jar:jar/newt.all.jar" name/someone/MyProject.java</tt>
 
* Then run your project. We assume your main class is <tt>name.someone.MyProject</tt>.
** Windows: Type <tt>java -classpath "jar\gluegen-rt.jar;jar\nativewindow.all.jar;jar\jogl.all.jar;jar\newt.all.jar;." -Djava.library.path=lib name.someone.MyProject</tt>
** Linux/MacOS X: Type <tt>java -classpath "jar/gluegen-rt.jar:jar/nativewindow.all.jar:jar/jogl.all.jar:jar/newt.all.jar:." -Djava.library.path=lib name.someone.MyProject</tt>


That's it!
That's it! You can now use the library in your project.

Revision as of 00:23, 6 March 2011

These instructions assume that you've created a project in your favorite IDE, and now you want your project to be able to use a JogAmp library like JOGL, JOCL, JOAL, or GlueGen. We use JOGL as an example below, but these instructions work equally well for any other JogAmp library.

Download a JogAmp library

If you haven't done so already, download and extract the JogAmp library you want to use. For example, to download and extract JOGL, see the instructions at Downloading and installing JOGL.

To use a JogAmp library you'll have to add its JAR files to the Java classpath and its native libraries to the Java library path. Each IDE has a slightly different way to do this, as we show below.

Please note that all JogAmp libraries depend on the GlueGen runtime libraries. These are included in every JogAmp library for convenience, but are only required once in the classpath and library path of your project.

Eclipse IDE

Create a user library

You can make your new Eclipse project depend directly on all the JARs and native libraries, but it's inconvenient to do that every time you create a new project. Creating a user library bundles all the files together so you can include them in one step.

  • Click "Window > Preferences", then select "Java > Build Path > User Libraries" on the left.
  • Click the "New..." button, type "JOGL" for the library name, and click "OK".
Create user library
  • Click the "Add JARs..." button, navigate to the directory where you've stored the JARs, select them, then click "Open".
  • Expand the jar in the list, double-click "Native library location", type the directory where native library files are stored, and click "OK".
Set native library locations
  • Click "OK" to exit Preferences dialog.

Add the user library to your project's dependencies

  • Right-click your project in the Package Explorer and clock "Properties".
  • Select "Java Build Path" and click the "Libraries" tab.
Add library to project
  • Click "Add Library...", select "User Library", click "Next", check "JOGL", and click "Finish".
Add JOGL library to project
  • Click "OK" to dismiss the Properties dialog.

That's it! You can now use the library in your project.

IntelliJ IDEA

Add a library dependency to your project

  • Click "File > Project Structure".
  • Select "Modules" on the left, then click the "Dependencies" tab on the right.
  • Click the "Add..." button, then click "Library...".
    Add library
  • Type "JOGL" as the library name.
  • Click "Attach JAR Directories...", navigate to the directory where you extracted the JARs and click "OK".
  • Click "OK" to dismiss the Configure Library dialog.
    Configure library
  • Click "OK" to dismiss the Project Structure dialog. The external libraries in your project should now look like this.
    External libraries

Add the native libraries to the run configuration

  • Click "Run > Edit Configurations".
  • Type -Djava.library.path=your/path/to/native/library/files in the "VM Parameters" box.
    Edit run configuration
  • Click "OK" to dismiss the Run/Debug Configurations dialog.

That's it! You can now use the library in your project.

NetBeans IDE

Create a library and add it to your project

  • Right-click your project and click "Properties".
  • Select "Libraries" on the left and click "Add Library...".
  • Click the "Create" button, then type "JOGL" for the library name and click "OK".
    Create library
  • Click "Add JAR/Folder...", then navigate to the directory you extracted the JAR files, select them and click "Add JAR/Folder".
  • Click "OK" to dismiss the Customize Library dialog.
  • Click "Add Library" to dismiss the Add Library dialog.
    Add library
  • Click "OK" to dismiss the Project Properties dialog. The libraries in your project should look like this.
    Libraries in project

Add the native libraries to the run configuration

  • Click "Run > Set Project Configuration > Customize...". Select "Run" on the left if it isn't selected already.
  • Type -Djava.library.path=your/path/to/native/library/files in the "VM Options" box.
    Native library path
  • Click "OK" to dismiss the Project Properties dialog.

That's it! You can now use the library in your project.

vi and other text editors

Create your project with the editor of your choice

  • For example, to open vi, simply type vi and press <return>.
  • Type all your code, then save it.

Compile and run your project from the command line

  • We assume your JOGL JAR files are in a directory called jar, and your JOGL native library files are in a directory called lib.
  • First compile your program. We assume all your code is in a single file called name/someone/MyProject.java.
    • Windows: Type javac -classpath "jar\gluegen-rt.jar;jar\nativewindow.all.jar;jar\jogl.all.jar;jar\newt.all.jar" name\someone\MyProject.java
    • Linux/MacOS X: Type javac -classpath "jar/gluegen-rt.jar:jar/nativewindow.all.jar:jar/jogl.all.jar:jar/newt.all.jar" name/someone/MyProject.java
  • Then run your project. We assume your main class is name.someone.MyProject.
    • Windows: Type java -classpath "jar\gluegen-rt.jar;jar\nativewindow.all.jar;jar\jogl.all.jar;jar\newt.all.jar;." -Djava.library.path=lib name.someone.MyProject
    • Linux/MacOS X: Type java -classpath "jar/gluegen-rt.jar:jar/nativewindow.all.jar:jar/jogl.all.jar:jar/newt.all.jar:." -Djava.library.path=lib name.someone.MyProject

That's it! You can now use the library in your project.