jME Maven Setup

I have crated a new tutorial at the wiki:

http://www.jmonkeyengine.com/wiki/doku.php?id=the_tutorials_-_jme_2



jME Maven Setup: http://www.jmonkeyengine.com/wiki/doku.php?id=jme_maven_setup



It’s far from complete but the the general idea is there, the guide is complete for a Linux setup, other OS will be addressed later because now I’m going to sleep. I know nothing about MacOS and don’t have access to it so if anyone is willing to fill that gap you are more than welcome.



Feedback really appreciated!

Wow, really detailed. I've added those two <exclude> lines to the pom.xml, so you can remove that part to simplify the process.

I think its pretty good :slight_smile:



a could of things you might want to think about:

  the first paragraph comes off a little 'grouchy' and could actually scare some potentials away from jME simply from all the issues you list.  (yes getting the libraries and stuff all figured out is a pain the first couple of times, I know I have banged my head for several hours; but after you get some experience you may find you can do it w/ your eyes closed.  also  the knowledge gained from having to deal w/ all the libraries is invaluable to jME and ANY future projects you may have :))



  you might want to have an estimated time to complete the tutorial, to the closest 15-30 mins is usually the norm.



looks like you put a lot of work into it, good tutorials can definitely be a make or break situation for ppl figuring it out. good job :slight_smile:

@ Irrisor:

Thanks for editing the pom.xml, I removed that part from the guide. By the way, there's a "mvn-lib-install" in the lib folder that shows how to install libraries into your local maven repository but the path to find the libs is wrong since it says "lib/lwjgl" but the file is already in the lib folder so the "lib/" should be removed from all the lines. It would be really nice if you could patch it.



@basixs

Hehe, yes you are right the first paragraph came off really grouchy, I changed it to make it more friendly.



Thanks both of you for your feedback  :). I also removed some lines from some example outputs since they served no purpose. I will keep improving it and fill the TODO's as I have some spare time but remember that anyone is welcome to help improving it since it's a wiki after all!

Tomygun said:
so the "lib/" should be removed from all the lines.

if you invoke "./libs/mvn-lib-install" from the jME root folder the script is just fine.

Well… yes you are right. I thought of that but also thought running it from the lib folder would be easier. Forget what I said, if it was done like that on purpose I'm sure it was decided with care so it's okay as it is.

Hey tomygun



Can you go through your tutorial and fix up all the paths that relate to you?  They should be like all the other tutorials and use a simple example when an absolute path is needed…


'/home/tomas/NetBeansProjects/jme2/trunk/lib'

I almost guarantee that is gonna get a newb or 2 ;)

Done. Replaced it with JME2_PATH.

thanx :slight_smile:

After sharing our points of view about the LWJGL files I modified the guide a little. Let me know what you think.



http://www.jmonkeyengine.com/wiki/doku.php?id=jme_maven_setup#lwjgl_native_libraries

nice, I like that you have pointed out the 'easy way' and 'proper way' (not easy and hard); thanx Tomygun and have a merry Christmas :slight_smile:



Sorry for hijacking that other thread, you were right to post here and I should have also…

Good thing you liked it, too bad I changed it again!



Merry Christmas to you too and as a present for everyone I completely modified the guide.



I solved all the issues involved in developing, running and deploying the project by providing a complete pom.xml. The project can be easily integrated into the IDE and doesn't require to configure the LWJGL path in the IDE. It also generates a *-release.zip file with the usual deployment people would expect, a jar file and a lib folder with all dependencies. To run the release just unzip and then do the "java -jar -Djava.library.path="./lib" yourjarfile.jar".



I really think that the guide as it is now would avoid all the issues that keep popping up while encouraging good practices and releaving the user of the tedious setups and it's also really fast and easy to follow.



Some images would help and adding the Eclipse setup is needed.



Let me know what you think and help me improve it.

Hello,

Very nice tutorial. It helped me a lot to configure my environment.

I created a new version of the pom file, based on yours. I removed the need to have a local jME installation. With this new pom file, the native libraries are in the repository and a copy is done during the compilation.

First advantage: the pom file doesn't have a jme2.home variable. So it's easier for the new users to use it. And if you move your jME installation, you don't have to modify all your projects.

Second advantage: the native libraries are in the repository. For each new project you don't have to worry about them. The download and installation in your new project is automatic.

Here is the pom file:


<?xml version="1.0" encoding="UTF-8"?>
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mypackage</groupId>
    <artifactId>jme-sample</artifactId>
   <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
   <name>jme-sample</name>
    <properties>
        <main.class>com.mypackage.jmesample.App</main.class>
    </properties>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemProperties>
                        <systemProperty>
                            <key>org.lwjgl.librarypath</key>
                            <value>${project.build.directory}/lib</value>
                        </systemProperty>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>${main.class}</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-2</version>
                <executions>
                    <execution>
                        <id>bundle-project-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <systemProperties>
                        <systemProperty>
                            <key>org.lwjgl.librarypath</key>
                            <value>${project.build.directory}/lib/</value>
                        </systemProperty>
                    </systemProperties>
                    <mainClass>${main.class}</mainClass>
                    <argument>-classpath</argument>
                    <!--
                        automatically creates the classpath using all project
                        dependencies, also adding the project build directory
                    -->
                    <classpath />
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.lwjgl</groupId>
                                    <artifactId>lwjgl</artifactId>
                                    <version>2.0rc1</version>
                                    <type>jar</type>
                                    <classifier>${build-type}</classifier>
                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.jmonkeyengine</groupId>
            <artifactId>jme</artifactId>
            <version>2.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>linux</id>
            <activation>
                <os>
                    <family>unix</family>
                    <name>linux</name>
                </os>
            </activation>
            <properties>
                <build-type>linux</build-type>
            </properties>
        </profile>
        <profile>
            <id>macosx</id>
            <activation>
                <os>
                    <family>unix</family>
                    <name>mac os x</name>
                </os>
            </activation>
            <properties>
                <build-type>macosx</build-type>
            </properties>
        </profile>
        <profile>
            <id>windows</id>
            <activation>
                <os>
                    <arch>x86</arch>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <build-type>windows</build-type>
            </properties>
        </profile>
    </profiles>
</project>



The native libraries are managed with several jar files, one per platform. The jar files are downloaded and unpacked during the compilation. You need to install them in your local repository using the following commands:
First create the jar files:


cd JME2_PATH/trunk/lib/lwjgl/native
cd linux
jar cvf ../linux.jar *.so
cd ../macosx
jar cvf ../macosx.jar *.jnilib
cd ../solaris
jar cvf ../solaris.jar *.so
cd ../windows
jar cvf ../windows.jar *.dll
cd ..


Then install the files in the local repository:


cd JME2_PATH/trunk
mvn install:install-file -Dfile=lib/lwjgl/native/linux.jar -DgroupId=org.lwjgl -DartifactId=lwjgl -Dversion=2.0rc1 -Dpackaging=jar -Dclassifier=linux
mvn install:install-file -Dfile=lib/lwjgl/native/macosx.jar -DgroupId=org.lwjgl -DartifactId=lwjgl -Dversion=2.0rc1 -Dpackaging=jar -Dclassifier=macosx
mvn install:install-file -Dfile=lib/lwjgl/native/solaris.jar -DgroupId=org.lwjgl -DartifactId=lwjgl -Dversion=2.0rc1 -Dpackaging=jar -Dclassifier=solaris
mvn install:install-file -Dfile=lib/lwjgl/native/windows.jar -DgroupId=org.lwjgl -DartifactId=lwjgl -Dversion=2.0rc1 -Dpackaging=jar -Dclassifier=windows



Here is the modified assembly.xml file:


<?xml version="1.0" encoding="UTF-8"?>
<assembly>
    <id>release-${build-type}</id>
    <formats>
        <format>zip</format>
    </formats>
    <files>
        <file>
            <source>${project.build.directory}/${project.artifactId}-${project.version}.jar</source>
            <outputDirectory>/</outputDirectory>
        </file>
    </files>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/lib</directory>
            <outputDirectory>lib</outputDirectory>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>


I modified the id in order to tell on which platform the file was created because the lib directory only contains the native libraries of the platform used to compile.

I hope my work can be useful.

edit: I made a mistake in the exec plug-in. The <executions> tag was useless and was creating an error during the build. I also replaced the <overWrite> tag of the unpack operation by a <overWriteIfNewer>. Thus the unpack operation is done only if the native libraries changes.