| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><meta name="keywords" content="documentation, install"><title>Starting a JME3 application from the command-line</title><link rel="stylesheet" href="./asciidoctor.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/simpleapplication_from_the_commandline.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Starting a JME3 application from the command-line</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#installing-the-jme3-framework">Installing the JME3 Framework</a></li><li><a href="#installing-with-git-easy-way">Installing with Git (easy way)</a></li><li><a href="#manual-download-hard-way">Manual Download (hard way)</a></li><li><a href="#sample-project-directory-structure">Sample Project Directory Structure</a></li><li><a href="#libraries">Libraries</a><ul class="sectlevel2"><li><a href="#sample-code">Sample Code</a></li></ul></li><li><a href="#build-and-run">Build and Run</a></li><li><a href="#recommended-asset-directory-structure">Recommended Asset Directory Structure</a></li><li><a href="#next-steps">Next Steps</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>Although we recommend the jMonkeyEngine <a href="../sdk.html">SDK</a> for developing JME3 games, you can use any IDE (integrated development environment) such as <a href="../jme3/setting_up_netbeans_and_jme3.html">NetBeans</a> or <a href="../jme3/setting_up_jme3_in_eclipse.html">Eclipse</a>, and even work freely from the command-line. Here is a generic IDE-independent “getting started” tutorial.</p></div></div></div>
- <div class="sect1"><h2 id="installing-the-jme3-framework">Installing the JME3 Framework</h2><div class="sectionbody"><div class="paragraph"><p>There are many ways to install the JME framework from the command-line, but for this tutorial we will narrow it down to two, the easy way and the hard way.</p></div></div></div>
- <div class="sect1"><h2 id="installing-with-git-easy-way">Installing with Git (easy way)</h2><div class="sectionbody"><div class="paragraph"><p>You can build JME3 from the sources. (Recommended for JME3 developers.) This example expects <a href="https://help.github.com/articles/set-up-git/">Git</a> to be installed on your system.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>mkdir jme3
- cd jme3
- // if you have a rsa key configured
- git clone [email protected]:jMonkeyEngine/jmonkeyengine.git
- // or
- // if you don't, but you'll be asked for credential after the next command
- git clone https://github.com/jMonkeyEngine/jmonkeyengine.git
- //can take a while
- // build the engine and install it in your local maven repo.
- ./gradlew install</code></pre></div></div>
- <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content">What is an <a href="https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/">RSA key</a>?</td></tr></table></div>
- <div class="paragraph"><p>The install command will install the built jars into your local maven repositories org.jmonkeyengine folder, which on Linux is ~/.m2, and on Windows might be in AppData, or in your home directory.</p></div>
- <div class="paragraph"><p>To use the engine in a game project, you can use <a href="https://hub.jmonkeyengine.org/t/bootmonkey-bootstrap-your-jme-project/37141">BootMonkey</a> or clone a template project from GitHub.</p></div>
- <div class="paragraph"><p>To use the template, first create a folder for your project:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>cd ..
- mkdir HelloJME3
- cd HelloJME3</code></pre></div></div>
- <div class="paragraph"><p>Next, clone one of these templates:</p></div>
- <div class="ulist"><ul><li><p><a href="https://github.com/Simsilica/Examples/tree/master/simple-jme">Simsilica/Examples</a></p></li><li><p><a href="https://github.com/Nehon/base-jme">Nehon/base-jme</a></p></li></ul></div>
- <div class="paragraph"><p>After cloning, open the <code>build.gradle</code> file and uncomment the <code>mavenLocal()</code> repository, change the version variable, and uncomment any dependencies you will need:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>repositories {
- //This is where jme3 dependencies are stored.
- jcenter()
- //Uncomment this if you install local dependencies.
- mavenLocal()
- //Uncomment this if you use external dependencies
- //mavenCentral()
- //Uncomment this if you use jme3-niftygui
- //maven{url 'http://nifty-gui.sourceforge.net/nifty-maven-repo'}
- }
- ext.jmeVersion = "[3.2,)"
- ...
- dependencies {
- compile "org.jmonkeyengine:jme3-core:$jmeVersion"
- compile "org.jmonkeyengine:jme3-desktop:$jmeVersion"
- compile "org.jmonkeyengine:jme3-lwjgl:$jmeVersion"
- //Those are jme3 additional library uncomment the ones you need
- //compile "org.jmonkeyengine:jme3-android-native:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-android:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-bullet-native-android:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-blender:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-bullet-native:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-bullet:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-effects:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-jogg:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-jogl:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-lwjgl3:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-networking:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-plugins:$jmeVersion"
- //compile "org.jmonkeyengine:jme3-terrain:$jmeVersion"
- //You need to uncomment nifty repository in the repositories section if you use this dependency
- //compile "org.jmonkeyengine:jme3-niftygui:$jmeVersion"
- runtime project(':assets')
- }
- ...</code></pre></div></div>
- <div class="paragraph"><p>For a detailed description of the separate jar files see <a href="../jme3/jme3_source_structure.html#structure_of_jmonkeyengine3_jars">this list</a>.</p></div>
- <div class="paragraph"><p>That’s it, you’re done. After the clone, you will have a project that contains a source package with a default blue cube JME3 app and a subproject that has the proper asset directory structure for your assets.</p></div>
- <div class="paragraph"><p>Build and run your project and you should see a blue cube.</p></div></div></div>
- <div class="sect1"><h2 id="manual-download-hard-way">Manual Download (hard way)</h2><div class="sectionbody"><div class="paragraph"><p>This example shows how to set up and run a simple application (HelloJME3) that depends on the jMonkeyEngine3 libraries.</p></div>
- <div class="paragraph"><p>The directory structure will look as follows:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>jme3/
- jme3/lib
- jme3/src
- ...
- HelloJME3/
- HelloJME3/lib
- HelloJME3/assets
- HelloJME3/src
- ...</code></pre></div></div>
- <div class="paragraph"><p>To install the development version of jme3, download the latest <a href="https://github.com/jMonkeyEngine/jmonkeyengine/releases">stable release</a>, unzip the folder into a directory named <code>jme3</code>. The filenames here are just an example, but they will always be something like <code>jME3.x-stable</code>.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>mkdir jme3
- cd jme3
- unzip jME3.2-stable.zip
- cd ..</code></pre></div></div></div></div>
- <div class="sect1"><h2 id="sample-project-directory-structure">Sample Project Directory Structure</h2><div class="sectionbody"><div class="paragraph"><p>First we set up the directory and source package structure for your game project. Note that the game project directory <code>HelloJME3</code> is on the same level as your <code>jme3</code> folder. In this example, we create a Java package that we call <code>mygame</code> in the source directory.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>mkdir HelloJME3
- mkdir HelloJME3/src
- mkdir HelloJME3/src/mygame</code></pre></div></div></div></div>
- <div class="sect2"><h3 id="libraries">Libraries</h3><div class="paragraph"><p>Next you copy the necessary JAR libraries from the download to your project. You only have to do this set of steps once every time you download a new JME3 build. For a detailed description of the separate jar files see <a href="../jme3/jme3_source_structure.html#structure_of_jmonkeyengine3_jars">this list</a>.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>mkdir HelloJME3/build
- mkdir HelloJME3/lib
- cp jme3/lib/*.* HelloJME3/lib</code></pre></div></div>
- <div class="sect2"><h3 id="sample-code">Sample Code</h3><div class="paragraph"><p>To test your setup, create the file <code>HelloJME3/src/mygame/HelloJME3.java</code> with any text editor, paste the following sample code, and save.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">package</span> <span class="namespace">mygame</span>;
- <span class="keyword">import</span> <span class="include">com.jme3.app.SimpleApplication</span>;
- <span class="keyword">import</span> <span class="include">com.jme3.material.Material</span>;
- <span class="keyword">import</span> <span class="include">com.jme3.math.Vector3f</span>;
- <span class="keyword">import</span> <span class="include">com.jme3.scene.Geometry</span>;
- <span class="keyword">import</span> <span class="include">com.jme3.scene.shape.Box</span>;
- <span class="keyword">import</span> <span class="include">com.jme3.math.ColorRGBA</span>;
- <span class="directive">public</span> <span class="type">class</span> <span class="class">HelloJME3</span> <span class="directive">extends</span> SimpleApplication {
- <span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> main(<span class="predefined-type">String</span><span class="type">[]</span> args){
- HelloJME3 app = <span class="keyword">new</span> HelloJME3();
- app.start();
- }
- <span class="annotation">@Override</span>
- <span class="directive">public</span> <span class="type">void</span> simpleInitApp() {
- <span class="predefined-type">Box</span> b = <span class="keyword">new</span> <span class="predefined-type">Box</span>(Vector3f.ZERO, <span class="integer">1</span>, <span class="integer">1</span>, <span class="integer">1</span>);
- Geometry geom = <span class="keyword">new</span> Geometry(<span class="string"><span class="delimiter">"</span><span class="content">Box</span><span class="delimiter">"</span></span>, b);
- Material mat = <span class="keyword">new</span> Material(assetManager,
- <span class="string"><span class="delimiter">"</span><span class="content">Common/MatDefs/Misc/Unshaded.j3md</span><span class="delimiter">"</span></span>);
- mat.setColor(<span class="string"><span class="delimiter">"</span><span class="content">Color</span><span class="delimiter">"</span></span>, ColorRGBA.Blue);
- geom.setMaterial(mat);
- rootNode.attachChild(geom);
- }
- }</code></pre></div></div></div></div>
- <div class="sect1"><h2 id="build-and-run">Build and Run</h2><div class="sectionbody"><div class="paragraph"><p>We build the sample application into the build directory…</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>cd HelloJME3
- javac -d build -cp "lib/eventbus.jar:lib/j-ogg-all.jar:lib/jme3-lwjgl.jar:lib/jme3-bullet.jar:lib/jinput.jar:lib/lwjgl.jar:lib/stack-alloc.jar:lib/vecmath.jar:lib/xpp3.jar:lib/jme3-blender.jar:lib/jme3-core.jar:lib/jme3-desktop.jar:lib/jme3-jogg.jar:lib/jme3-plugins.jar:lib/jme3-terrain.jar:lib/jme3-testdata.jar:lib/jme3-niftygui.jar:lib/nifty-default-controls.jar:lib/nifty-examples.jar:lib/nifty-style-black.jar:lib/nifty.jar:." src/mygame/HelloJME3.java</code></pre></div></div>
- <div class="paragraph"><p>… and run it.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>cd build
- java -cp "../lib/eventbus.jar:../lib/j-ogg-all.jar:../lib/jme3-lwjgl.jar:../lib/jme3-bullet.jar:../lib/jinput.jar:../lib/lwjgl.jar:../lib/stack-alloc.jar:../lib/vecmath.jar:../lib/xpp3.jar:../lib/jme3-blender.jar:../lib/jme3-core.jar:../lib/jme3-desktop.jar:../lib/jme3-jogg.jar:../lib/jme3-plugins.jar:../lib/jme3-terrain.jar:../lib/jme3-testdata.jar:../lib/jme3-niftygui.jar:../lib/nifty-default-controls.jar:../lib/nifty-examples.jar:../lib/nifty-style-black.jar:../lib/nifty.jar:." mygame/HelloJME3</code></pre></div></div>
- <div class="admonitionblock note"><table><tr><td class="icon"><i class="fa icon-note" title="Note"></i></td><td class="content">If you use Windows, the classpath separator is <kbd>\</kbd> instead of <kbd>/</kbd>.</td></tr></table></div>
- <div class="paragraph"><p>If a settings dialog pops up, confirm the default settings. You should now see a simple window with a 3-D cube. Use the mouse and the WASD keys to move. It works!</p></div></div></div>
- <div class="sect1"><h2 id="recommended-asset-directory-structure">Recommended Asset Directory Structure</h2><div class="sectionbody"><div class="paragraph"><p>For <a href="../jme3/intermediate/multi-media_asset_pipeline.html">multi-media files, models, and other assets</a>, we recommend creating the following project structure:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>cd HelloJME3
- mkdir assets
- mkdir assets/Interface
- mkdir assets/Materials
- mkdir assets/MatDefs
- mkdir assets/Models
- mkdir assets/Scenes
- mkdir assets/Shaders
- mkdir assets/Sounds
- mkdir assets/Textures</code></pre></div></div>
- <div class="paragraph"><p>This directory structure will allow <a href="../jme3/intermediate/simpleapplication.html">SimpleApplication</a>'s default <a href="../jme3/advanced/asset_manager.html">AssetManager</a> to load media files from your <code>assets</code> directory, like in this example:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code>import com.jme3.scene.Spatial;
- ...
- Spatial elephant = assetManager.loadModel("Models/Elephant/Elephant.meshxml");
- rootNode.attachChild(elephant);
- ...</code></pre></div></div>
- <div class="paragraph"><p>You will learn more about the asset manager and how to customize it later. For now feel free to structure your assets (images, textures, models) into further sub-directories, like in this example the <code>assets/models/Elephant</code> directory that contains the <code>elephant.mesh.xml</code> model and its materials.</p></div></div></div>
- <div class="sect1"><h2 id="next-steps">Next Steps</h2><div class="sectionbody"><div class="paragraph"><p>Now follow the <a href="../jme3.html">tutorials</a> and write your first jMonkeyEngine game.</p></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
- apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
- indexName: 'jmonkeyengine',
- inputSelector: '#doc-search',
- debug: false // Set debug to true if you want to inspect the dropdown
- });</script></body></html>
|