This tutorial shows how to set up an IDE (integrated development environment) to create Java 3D games with the jMonkeyEngine framework (jME). An IDE integrates all your development tools (compiler, debugger, profiler, editor, docs, etc) into one graphical interface and spares you some of the complications of the commandline.
This tutorial is intended to work with jME 2.0 and NetBeans IDE 6.5 or better. Download the NetBeans IDE for Java SE bundle for free from http://www.netbeans.org. jME 2.0 is deprecated as of September 2009. But as long as the download is still available this still works.
See also: all_netbeans_tutorials
This is a simplified overview of the file structure we are going to set up by going through this tutorial.
lwjgl.jar and lwjgl.dll as examples. hello3d/test/HelloWorld.java.
NetBeansProjects/
Hello3D/
build/classes/hello3d/test/HelloWorld.class
build.xml
dist/
HelloApp.jar
Hello3D.jar
lib/ ... (JAR files)
natives/ ... (native files)
one-jar-ant-task.xml
one-jar.mf
src/hello3d/test/HelloWorld.java
jME2/
jME_2.0_Complete_(r4093)/
jME_2.0.jar
lib/
lwjgl.jar (and more JARs...)
natives/
lwjgl.dll (and more natives...)
run_jME.bat
run_jME.sh
jME_2.0_Distribution_(r4093)/
jme.jar (and more JARs...)
jME_2.0_JavaDoc_(r4093)/
index.html (and more docs...)
jME_2.0_Sources/
src/
lib/
lwgl/ ...
lwjgl.jar ...
native/lwjgl.dll ...
mvn-lib-install
pom.xml
build.xml
OneJar/
one-jar-ant-task-0.96.jar
We will download two files: The archive jME_2.0_Complete contains all JARs and native libraries needed to use jME. I recommend to also download the optional archive jME_2.0_JavaDoc. It contains jME developer documentation and is very helpful.
Note: I write * instead of the explicit version number.
Steps:
jME2.jME2 directory.
Next we create a project and configure its class path and java library path.
We will set up an empty NetBeans project. We'll configure it to find jME libraries on the classpath and to find native dynamic libraries on the java.library.path.
In NetBeans:
File > New Project from the menu. Java > Java Application. Click Next.C:\Users\Joe\Documents\NetBeansProjects\The Hello3D project now opens in the Projects window.
Next we add all jME JAR libraries to the project's classpath:
jME2\jME_2.0_Complete_(r4093)\lib\ directory. Multi-select all .jar files (ctrl-click). jME2\jME_2.0_Complete_(r4093)\ directory and select the file jME_2.0.jar. Look into the Projects window and open the library node: Here you see the JAR libraries on your project's classpath.
Next we add all native dynamic libraries to the Java Library Path:
-Djava.library.path="../jME2/jME_2.0_Complete_(r4093)/lib/natives/"
Next we fill in test code and run the project.
To test the set-up, we will use the HelloWorld sample file from the jME tutorial.
In NetBeans:
hello3d.test. hello3d.test node, and select “New > Java class”. HelloWorld.java. package jmetest.TutorialGuide; to package hello3d.test;
This file is all you need to create a fully working jME application. Let's build and run the HelloWorld sample.
You can copy any of the files from TutorialGuide in the same way and run any sample code that has a main method. (Note: TestPongCool.java also requires ExplosionFactory.java to work.)
The jME-2.0.jar also contains demos that show well what jME is capable of. (This step is optional.)
cd jME2/jME_2.0_Complete*/./run_jME.sh in a Terminal window.run_jME.bat.java -jar -Xmx256m -Djava.library.path=“lib/natives” jME_2.0.jar on the commandline.The jmetest.TestChooser starts. Select your screen settings and select one of the demos to run. See also: zathrasbeginnersfaq.
Browse all the source code here and learn how to use each feature from examples: http://jmonkeyengine.googlecode.com/svn/trunk/src/jmetest/
In this step, you will learn how to activate useful IDE features, such as automatic code completion and javadoc pop-ups.
First we configure NetBeans to find jME's developer documentation.
jME2 directory.jME_2.0.jar entry, and click Edit.jME2\jME_2.0_JavaDoc_(r4093)\.
Configuring NetBeans to find the Javadoc activates handy development features: You are now able to use automatic code completion and documentation pop-ups in this jME project in the IDE.
Next we will give the NetBeans Navigator access to the the jME sources.
http://jmonkeyengine.googlecode.com/svn/trunk trunk. Wait for the source files to finish downloading. If NetBeans asks whether it should open the new project, you can say yes. (See below)
jME_2.0.jar entry, and click Edit.jME2\trunk\.Configuring NetBeans to find the sources allows you to learn a lot from reading the actual code.
Let's try out some of the IDE's productivity features:
SimpleGame). Press ctrl-space to see available methods and documentation. rootNode) to open the source file where it was defined.Learn more form http://www.netbeans.org/kb/.
Now that you know how to run a jME sample file, and have access to sample code, you can start your own game.
Tips:
Java Desktop Application category instead of a vanilla Java SE project. It creates a Swing Application Framework-based project that already comes with a main window and some menus.
Start button that creates a new instance of your game. You can also add cool graphics and Settings/Save/Load buttons here.
It's fine to use SimpleGame for quick demos. By looking at existing samples, you see the underlying inheritance structure, and along the same lines, you create a custom subclass of BaseGame for your application. Learn more from the jME Users Guide and zathrasbeginnersfaq.
During development it's enough to run your Java application from the IDE. But for a release you want other people to be able to run it outside the IDE. You need an executable distribution, optimally it should be only one file.
Advanced Tip: Do you want to save space and create smaller executables? Then remove the complete jME-2.0.jar from the Libraries node and instead add the individual JARs from the jME_2.0_Distribution directory. The jME_2.0_Distribution is 15MB smaller because it doesn't contain any examples or sample media.
OneJAR (http://one-jar.sourceforge.net/) provides a way to package your classes, liberaries and native libs in one jar! Here is how to set up NetBeans to automate the process. Let's call the single-JAR file HelloApp.jar (stand-alone) to distinguish it from the previously created Hello3D.jar (not fully stand-alone because of the necessary libraries).
OneJar next to the Hello3D directory.one-jar-ant-task-0.96.jar from one-jar-sdk to OneJar. one-jar-ant-task.xml from one-jar-sdk to Hello3DHello3D/one-jar-ant-task.xml to say value="../OneJar"
Create a file onejar.mf in the Hello3D directory, with the following content:
Manifest-Version: 1.0 Ant-Version: Apache Ant 1.7.1 Main-Class: com.simontuffs.onejar.Boot Class-Path: lib/gluegen-rt.jar lib/jinput.jar lib/jogl.jar lib/jorbis- 0.0.17.jar lib/lwjgl.jar lib/lwjgl_util.jar lib/lwjgl_util_applet.jar lib/swt.jar lib/jME_2.0.jar lib/swing-layout-1.0.3.jar lib/one-jar-a nt-task-0.96.jar One-Jar-Main-Class: hello3d.test.HelloWorld
Open your project's build.xml and add the following before the closing </project> tag:
<import file="one-jar-ant-task.xml" /> <echo>OneJAR: Creating distributable OneJAR</echo> <target name="dist-onejar" depends="jar" description="Creates a standalone OneJAR distribution"> <echo>OneJAR: Copying natives to ${dist.jar.dir} </echo> <copy todir="${dist.jar.dir}/natives"> <fileset dir="../jME2/jME_2.0_Complete_(r4093)/lib/natives/" /> </copy> <echo>OneJAR: Composing HelloApp.jar</echo> <one-jar destfile="${dist.jar.dir}/HelloApp.jar" manifest="onejar.mf"> <main> <fileset dir="${build.classes.dir}/" /> </main> <lib> <fileset file="${dist.jar.dir}/lib/*.*" /> </lib> <binlib> <fileset file="${dist.jar.dir}/natives/*.*" /> </binlib> </one-jar> <echo>OneJAR: Done. Run the file using: java -jar -Xmx256m HelloApp.jar </echo> </target>
Go to the Run menu and Clean and Build the project (or use the toolbar button). A stand-alone HelloApp.jar is now automatically created in the dist directory everytime you build.
You can customize the build dependency of this ant target if you want to speed up your development build cycle. To call the dist-onejar target manually:
build.xml filebuild.xml and select Run Target > Other Targets > dist-onejar
You can also assign a shortcut to your custom target.
build.xml filebuild.xml to list all targets.
HelloApp.bat in the dist directory, with the content:java -jar -Xmx256m HelloApp.jar
HelloApp.sh in the dist directory, with the content:#!/bin/sh java -jar -Xmx256m HelloApp.jar
/Developer/Applications/Utilities/Jar Bundler and enter the following:(Work in progress)
How to activate Java Web Start:
Everytime you Clean & Build the project (from Run menu, or click toolbar button), NetBeans will create the JAR and a distributable JNLP file in the dist directory. (TODO: more details: How to link the dynamic libraries? Signing?)
Learn more here: Deploying jME Applications with Webstart
Advanced users may want to build jME themselves from the sources. If you haven't downloaded the sources earlier as described above, do so now:
NetBeans Menu: Team > Subversion > Checkout, enter data from this page
Since the project contains a pom.xml file, NetBeans recognizes the project as Maven project and you can open it directly.
Now follow the instructions from jme_maven_setup:
lib/mvn-lib-install!! mvn clean installAn alternative, if you are more of an Ant whiz: Rename the pom.xml file to whatever (then it will no longer be recognized as a Maven project) and create a “Free-Form Java Project” in NetBeans like it is described here for NetBeans 6.5.