2
0

simpleapplication_from_the_commandline.adoc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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:jme3/setting_up_netbeans_and_jme3.adoc[NetBeans] or xref:jme3/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. jcenter()
  42. //Uncomment this if you install local dependencies.
  43. mavenLocal()
  44. //Uncomment this if you use external dependencies
  45. //mavenCentral()
  46. //Uncomment this if you use jme3-niftygui
  47. //maven{url 'http://nifty-gui.sourceforge.net/nifty-maven-repo'}
  48. }
  49. ext.jmeVersion = "[3.2,)"
  50. ...
  51. dependencies {
  52. compile "org.jmonkeyengine:jme3-core:$jmeVersion"
  53. compile "org.jmonkeyengine:jme3-desktop:$jmeVersion"
  54. compile "org.jmonkeyengine:jme3-lwjgl:$jmeVersion"
  55. //Those are jme3 additional library uncomment the ones you need
  56. //compile "org.jmonkeyengine:jme3-android-native:$jmeVersion"
  57. //compile "org.jmonkeyengine:jme3-android:$jmeVersion"
  58. //compile "org.jmonkeyengine:jme3-bullet-native-android:$jmeVersion"
  59. //compile "org.jmonkeyengine:jme3-blender:$jmeVersion"
  60. //compile "org.jmonkeyengine:jme3-bullet-native:$jmeVersion"
  61. //compile "org.jmonkeyengine:jme3-bullet:$jmeVersion"
  62. //compile "org.jmonkeyengine:jme3-effects:$jmeVersion"
  63. //compile "org.jmonkeyengine:jme3-jogg:$jmeVersion"
  64. //compile "org.jmonkeyengine:jme3-jogl:$jmeVersion"
  65. //compile "org.jmonkeyengine:jme3-lwjgl3:$jmeVersion"
  66. //compile "org.jmonkeyengine:jme3-networking:$jmeVersion"
  67. //compile "org.jmonkeyengine:jme3-plugins:$jmeVersion"
  68. //compile "org.jmonkeyengine:jme3-terrain:$jmeVersion"
  69. //You need to uncomment nifty repository in the repositories section if you use this dependency
  70. //compile "org.jmonkeyengine:jme3-niftygui:$jmeVersion"
  71. runtime project(':assets')
  72. }
  73. ...
  74. ----
  75. For a detailed description of the separate jar files see xref:jme3/jme3_source_structure#structure_of_jmonkeyengine3_jars,this list].
  76. 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.
  77. Build and run your project and you should see a blue cube.
  78. == Manual Download (hard way)
  79. This example shows how to set up and run a simple application (HelloJME3) that depends on the jMonkeyEngine3 libraries.
  80. The directory structure will look as follows:
  81. [source]
  82. ----
  83. jme3/
  84. jme3/lib
  85. jme3/src
  86. ...
  87. HelloJME3/
  88. HelloJME3/lib
  89. HelloJME3/assets
  90. HelloJME3/src
  91. ...
  92. ----
  93. 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`.
  94. [source]
  95. ----
  96. mkdir jme3
  97. cd jme3
  98. unzip jME3.2-stable.zip
  99. cd ..
  100. ----
  101. == Sample Project Directory Structure
  102. 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.
  103. [source]
  104. ----
  105. mkdir HelloJME3
  106. mkdir HelloJME3/src
  107. mkdir HelloJME3/src/mygame
  108. ----
  109. == Libraries
  110. 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 xref:jme3/jme3_source_structure#structure_of_jmonkeyengine3_jars,this list].
  111. [source]
  112. ----
  113. mkdir HelloJME3/build
  114. mkdir HelloJME3/lib
  115. cp jme3/lib/*.* HelloJME3/lib
  116. ----
  117. === Sample Code
  118. To test your setup, create the file `HelloJME3/src/mygame/HelloJME3.java` with any text editor, paste the following sample code, and save.
  119. [source,java]
  120. ----
  121. package mygame;
  122. import com.jme3.app.SimpleApplication;
  123. import com.jme3.material.Material;
  124. import com.jme3.math.Vector3f;
  125. import com.jme3.scene.Geometry;
  126. import com.jme3.scene.shape.Box;
  127. import com.jme3.math.ColorRGBA;
  128. public class HelloJME3 extends SimpleApplication {
  129. public static void main(String[] args){
  130. HelloJME3 app = new HelloJME3();
  131. app.start();
  132. }
  133. @Override
  134. public void simpleInitApp() {
  135. Box b = new Box(Vector3f.ZERO, 1, 1, 1);
  136. Geometry geom = new Geometry("Box", b);
  137. Material mat = new Material(assetManager,
  138. "Common/MatDefs/Misc/Unshaded.j3md");
  139. mat.setColor("Color", ColorRGBA.Blue);
  140. geom.setMaterial(mat);
  141. rootNode.attachChild(geom);
  142. }
  143. }
  144. ----
  145. == Build and Run
  146. We build the sample application into the build directory…
  147. [source]
  148. ----
  149. cd HelloJME3
  150. 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
  151. ----
  152. … and run it.
  153. [source]
  154. ----
  155. cd build
  156. 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
  157. ----
  158. NOTE: If you use Windows, the classpath separator is kbd:[\ ] instead of kbd:[/].
  159. 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!
  160. == Recommended Asset Directory Structure
  161. For xref:tutorials:intermediate/multi-media_asset_pipeline.adoc[multi-media files, models, and other assets], we recommend creating the following project structure:
  162. [source]
  163. ----
  164. cd HelloJME3
  165. mkdir assets
  166. mkdir assets/Interface
  167. mkdir assets/Materials
  168. mkdir assets/MatDefs
  169. mkdir assets/Models
  170. mkdir assets/Scenes
  171. mkdir assets/Shaders
  172. mkdir assets/Sounds
  173. mkdir assets/Textures
  174. ----
  175. This directory structure will allow xref:jme3/intermediate/simpleapplication.adoc[SimpleApplication]'s default xref:jme3/advanced/asset_manager.adoc[AssetManager] to load media files from your `assets` directory, like in this example:
  176. [source]
  177. ----
  178. import com.jme3.scene.Spatial;
  179. ...
  180. Spatial elephant = assetManager.loadModel("Models/Elephant/Elephant.meshxml");
  181. rootNode.attachChild(elephant);
  182. ...
  183. ----
  184. 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.
  185. == Next Steps
  186. Now follow the xref:tutorials:beginner/beginner.adoc[tutorials] and write your first jMonkeyEngine game.