simpleapplication_from_the_commandline.adoc 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. = Starting a JME3 application from the command-line
  2. :revnumber: 2.0
  3. :revdate: 2020/07/15
  4. :keywords: documentation, install
  5. Although we recommend the jMonkeyEngine xref:sdk:sdk.adoc[SDK] for developing JME3 games, you can use any IDE (integrated development environment) such as xref:getting-started/setting_up_netbeans_and_jme3.adoc[NetBeans] or xref:getting-started/setting_up_jme3_in_eclipse.adoc[Eclipse], and even work freely from the command-line. Here is a generic IDE-independent "`getting started`" tutorial.
  6. == Installing the JME3 Framework
  7. 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.
  8. == Installing with Git (easy way)
  9. You can build JME3 from the sources. (Recommended for JME3 developers.) This example expects link:https://help.github.com/articles/set-up-git/[Git] to be installed on your system.
  10. [source]
  11. ----
  12. mkdir jme3
  13. cd jme3
  14. // if you have a rsa key configured
  15. git clone [email protected]:jMonkeyEngine/jmonkeyengine.git
  16. // or
  17. // if you don't, but you'll be asked for credential after the next command
  18. git clone https://github.com/jMonkeyEngine/jmonkeyengine.git
  19. //can take a while
  20. // build the engine and install it in your local maven repo.
  21. ./gradlew install
  22. ----
  23. TIP: What is an link:https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/[RSA key]?
  24. 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.
  25. To use the engine in a game project, you can use link:https://hub.jmonkeyengine.org/t/bootmonkey-bootstrap-your-jme-project/37141[BootMonkey] or clone a template project from GitHub.
  26. To use the template, first create a folder for your project:
  27. [source]
  28. ----
  29. cd ..
  30. mkdir HelloJME3
  31. cd HelloJME3
  32. ----
  33. Next, clone one of these templates:
  34. * link:https://github.com/Simsilica/Examples/tree/master/simple-jme[Simsilica/Examples]
  35. * link:https://github.com/Nehon/base-jme[Nehon/base-jme]
  36. After cloning, open the `build.gradle` file and uncomment the `mavenLocal()` repository, change the version variable, and uncomment any dependencies you will need:
  37. [source]
  38. ----
  39. repositories {
  40. //This is where jme3 dependencies are stored.
  41. mavenCentral()
  42. //Uncomment this if you install local dependencies.
  43. mavenLocal()
  44. //Uncomment this if you use jme3-niftygui
  45. //maven{url 'http://nifty-gui.sourceforge.net/nifty-maven-repo'}
  46. }
  47. ext.jmeVersion = "[3.3,)"
  48. ...
  49. dependencies {
  50. compile "org.jmonkeyengine:jme3-core:$jmeVersion"
  51. compile "org.jmonkeyengine:jme3-desktop:$jmeVersion"
  52. compile "org.jmonkeyengine:jme3-lwjgl:$jmeVersion"
  53. //Those are jme3 additional library uncomment the ones you need
  54. //compile "org.jmonkeyengine:jme3-android-native:$jmeVersion"
  55. //compile "org.jmonkeyengine:jme3-android:$jmeVersion"
  56. //compile "org.jmonkeyengine:jme3-bullet-native-android:$jmeVersion"
  57. //compile "org.jmonkeyengine:jme3-blender:$jmeVersion"
  58. //compile "org.jmonkeyengine:jme3-bullet-native:$jmeVersion"
  59. //compile "org.jmonkeyengine:jme3-bullet:$jmeVersion"
  60. //compile "org.jmonkeyengine:jme3-effects:$jmeVersion"
  61. //compile "org.jmonkeyengine:jme3-jogg:$jmeVersion"
  62. //compile "org.jmonkeyengine:jme3-jogl:$jmeVersion"
  63. //compile "org.jmonkeyengine:jme3-lwjgl3:$jmeVersion"
  64. //compile "org.jmonkeyengine:jme3-networking:$jmeVersion"
  65. //compile "org.jmonkeyengine:jme3-plugins:$jmeVersion"
  66. //compile "org.jmonkeyengine:jme3-terrain:$jmeVersion"
  67. //You need to uncomment nifty repository in the repositories section if you use this dependency
  68. //compile "org.jmonkeyengine:jme3-niftygui:$jmeVersion"
  69. runtime project(':assets')
  70. }
  71. ...
  72. ----
  73. include::partial$source-structure-link.adoc[]
  74. 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.
  75. Build and run your project and you should see a blue cube.
  76. == Manual Download (hard way)
  77. This example shows how to set up and run a simple application (HelloJME3) that depends on the jMonkeyEngine3 libraries.
  78. The directory structure will look as follows:
  79. [source]
  80. ----
  81. jme3/
  82. jme3/lib
  83. jme3/src
  84. ...
  85. HelloJME3/
  86. HelloJME3/lib
  87. HelloJME3/assets
  88. HelloJME3/src
  89. ...
  90. ----
  91. To install the development version of jme3, download the latest link:https://github.com/jMonkeyEngine/jmonkeyengine/releases[stable release], unzip the folder into a directory named `jme3`. The filenames here are just an example, but they will always be something like `jME3.x-stable`.
  92. [source]
  93. ----
  94. mkdir jme3
  95. cd jme3
  96. unzip jME3.2-stable.zip
  97. cd ..
  98. ----
  99. == Sample Project Directory Structure
  100. First we set up the directory and source package structure for your game project. Note that the game project directory `HelloJME3` is on the same level as your `jme3` folder. In this example, we create a Java package that we call `mygame` in the source directory.
  101. [source]
  102. ----
  103. mkdir HelloJME3
  104. mkdir HelloJME3/src
  105. mkdir HelloJME3/src/mygame
  106. ----
  107. == Libraries
  108. 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.
  109. include::partial$source-structure-link.adoc[]
  110. [source]
  111. ----
  112. mkdir HelloJME3/build
  113. mkdir HelloJME3/lib
  114. cp jme3/lib/*.* HelloJME3/lib
  115. ----
  116. === Sample Code
  117. To test your setup, create the file `HelloJME3/src/mygame/HelloJME3.java` with any text editor, paste the following sample code, and save.
  118. [source,java]
  119. ----
  120. package mygame;
  121. import com.jme3.app.SimpleApplication;
  122. import com.jme3.material.Material;
  123. import com.jme3.math.Vector3f;
  124. import com.jme3.scene.Geometry;
  125. import com.jme3.scene.shape.Box;
  126. import com.jme3.math.ColorRGBA;
  127. public class HelloJME3 extends SimpleApplication {
  128. public static void main(String[] args){
  129. HelloJME3 app = new HelloJME3();
  130. app.start();
  131. }
  132. @Override
  133. public void simpleInitApp() {
  134. Box b = new Box(Vector3f.ZERO, 1, 1, 1);
  135. Geometry geom = new Geometry("Box", b);
  136. Material mat = new Material(assetManager,
  137. "Common/MatDefs/Misc/Unshaded.j3md");
  138. mat.setColor("Color", ColorRGBA.Blue);
  139. geom.setMaterial(mat);
  140. rootNode.attachChild(geom);
  141. }
  142. }
  143. ----
  144. == Build and Run
  145. We build the sample application into the build directory…
  146. [source]
  147. ----
  148. cd HelloJME3
  149. 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
  150. ----
  151. … and run it.
  152. [source]
  153. ----
  154. cd build
  155. 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
  156. ----
  157. NOTE: If you use Windows, the classpath separator is kbd:[\ ] instead of kbd:[/].
  158. 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!
  159. == Recommended Asset Directory Structure
  160. For xref:tutorials:concepts/multi-media_asset_pipeline.adoc[multi-media files, models, and other assets], we recommend creating the following project structure:
  161. [source]
  162. ----
  163. cd HelloJME3
  164. mkdir assets
  165. mkdir assets/Interface
  166. mkdir assets/Materials
  167. mkdir assets/MatDefs
  168. mkdir assets/Models
  169. mkdir assets/Scenes
  170. mkdir assets/Shaders
  171. mkdir assets/Sounds
  172. mkdir assets/Textures
  173. ----
  174. This directory structure will allow xref:core:app/simpleapplication.adoc[SimpleApplication]'s default xref:core:/asset/asset_manager.adoc[AssetManager] to load media files from your `assets` directory, like in this example:
  175. [source]
  176. ----
  177. import com.jme3.scene.Spatial;
  178. ...
  179. Spatial elephant = assetManager.loadModel("Models/Elephant/Elephant.meshxml");
  180. rootNode.attachChild(elephant);
  181. ...
  182. ----
  183. 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 `assets/models/Elephant` directory that contains the `elephant.mesh.xml` model and its materials.
  184. == Next Steps
  185. Now follow the xref:tutorials:beginner/beginner.adoc[tutorials] and write your first jMonkeyEngine game.