Search code examples
javamavenmaven-2build-processjogl

Maven and the JOGL library?


I've been studying Maven in my free time over the last several days but can't seem to figure out how to organize a project so that the JOGL libraries are used. I would preferably like the following:

  1. Automatically download, if necessary, the OS-specific JOGL zip file from here (contains 4 jar files and some native library files (.so/.dll)); or depend on a Maven project which is a wrapper of one of the files.
  2. Unzip that zip file appropriately, so that:
    1. the jar files are added to the classpath and deployed as necessary, and
    2. the native library files are added to the final jar file (would this enable them to be automatically used, or would I need something more involved?)

I think part of my problem is that I don't fully understand the use of JOGL, where to place the native libraries when running the code, etc. I need to go back to the basics and write a JOGL hello world, compile it from the command line and run it from the command line to see exactly what it requires as far as directory placement of the native libraries; I may go do that right now, actually.

With item 1, I've found some OS-specific features; Maven profiles can be activated based on properties of the system, which include the operating system. So then I could activate a Windows profile which has a dependency of the Windows-specific JOGL library, same for the Linux, and both having a 64-bit alter ego. (Activation official docs / unofficial docs.)

I have tried creating a Maven repository based on a JOGL jar file, and then adding the JOGL jar file project as a dependency of my project; the dependency is downloaded, but not used. I have no idea where the jar file goes or how to use it, unpack it, etc. Here is the command I used.

So, in short: JOGL consists of four .jar files and some native libraries. How can I integrate those files into my Maven project so that I can write a JOGL application with Maven handling my build process? Furthermore, how can I use a different set of files depending on the operating system, because of course the native libraries and even the .jar files differ between Windows, Linux and Mac.


Solution

  • Jogamp now contains support for Maven, for the jogl components (jocl and joal support is forthcoming). As of 2.0-rc11, packages are pushed to Maven Central.

    Just put this to your pom:

     <dependencies>
       <dependency>
         <groupId>org.jogamp.gluegen</groupId>
         <artifactId>gluegen-rt-main</artifactId>
         <version>2.0-rc11</version>
       </dependency>
       <dependency>
         <groupId>org.jogamp.jogl</groupId>
         <artifactId>jogl-all-main</artifactId>
         <version>2.0-rc11</version>
       </dependency>
     </dependencies>
    

    Maven will pull all of the dependencies the next time you attempt to build the project.

    Read more here on the wiki