Success with Maven 2 and NetBeans 6.1 :)

This made me so happy I thought I should share it with the rest of you.



First of all, I like NetBeans 6.1, Maven 2 and the Maven plugin that adds support for the latter to the former. This is for people who have this is common with me (or want to try something new) and would like to use Maven for projects that use jMonkeyEngine.



My goal was clear: Create a portable project structure. To be portable, the project structure should not require anyone to install non-mavenized jars (such as jME and lwjgl) into his or her local repository.



Here's the recipe:


  1. Create a maven project (use NB to do this if you like).
  2. Copy all of lwjgl's native dependencies (for your platform) into your project's base directory.
  3. Create a directory in your project's base directory called "lib".
  4. Copy all the jars from the releases of jMonkeyEngine and lwjgl into lib.
  5. Add the following to the dependencies section in your pom:


      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-audio</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-audio.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-awt</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-awt.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-collada</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-collada.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-editors</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-editors.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-effects</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-effects.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-font</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-font.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-gamestates</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-gamestates.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-model</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-model.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-scene</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-scene.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-terrain</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-terrain.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jme</groupId>
         <artifactId>jme-xml</artifactId>
         <version>1.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jme-xml.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>lwjgl</groupId>
         <artifactId>lwjgl</artifactId>
         <version>1.1.4</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/lwjgl.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>lwjgl</groupId>
         <artifactId>lwjgl_test</artifactId>
         <version>1.1.4</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/lwjgl_test.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>lwjgl</groupId>
         <artifactId>lwjgl_util</artifactId>
         <version>1.1.4</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/lwjgl_util.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>lwjgl</groupId>
         <artifactId>lwjgl_util_applet</artifactId>
         <version>1.1.4</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/lwjgl_util_applet.jar</systemPath>
      </dependency>
      <dependency>
         <groupId>jinput</groupId>
         <artifactId>jinput</artifactId>
         <version>unknown</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jinput.jar</systemPath>
      </dependency>


6. Create a class containing a main method that uses jMonkeyEngine. If you don't have anything, just copy and paste one of the demos.
7. Right-click on said class and select "Run File".

Now I'll duck for cover while all the Maven purists flame me for abusing the system scope.  :P

how does this handle native dependencies? - especially per platform?

Hi Matzon.



I've been following the maven discussions over at lwjgl. You seem to be one of those people that doesn't bother doing something if it can't be done perfectly. What I have done is successfully created a build environment for jME projects, not a deployment environment. You seem to have a problem with this, which is why you refuse to upload lwjgl to the maven repository. How many times does someone need to deploy a project anyway? Let's face it, most projects don't make it that far, but let's help developers get closer anyway, by allowing them to continue using Maven if that's their preferred build tool.

Now you have to get dependencies 2 places instead of one
Would you mind telling me one place where I can get all of my projects' dependencies?

Fwiw, I put the blame squarely at the dependency managers, they need to support packages that don't fit their limited universe.
I agree wholeheartedly. JNI is an integral part of Java and deserves to be a first class citizen of any build system that purports to solve the dependency management problem.

Matzon, there is no need to debate my solution (first post). I am not arguing for mavenization of jME or lwjgl. It is simply a means by which maven and jME can work side by side rather than being mutually exclusive. And if anything it takes the pressure off you and the jME developers.

This is getting a little silly. :)  Maybe it could be taken offline before it turns into a flameā€¦

I don't mind that. How about deleting all but the first post then locking the thread? I would hate to see this contribution disappear.