project_creation.adoc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. = jMonkeyEngine SDK: Creating Projects
  2. :revnumber: 2.0
  3. :revdate: 2020/07/09
  4. :keywords: documentation, project, deployment, sdk
  5. The jMonkeyEngine SDK makes it easy to get started with developing 3-D games based on the jMonkeyEngine.
  6. == Creating a New jMonkeyEngine Project
  7. . Choose `menu:File[New Project]` from the main menu.
  8. . In the New Project Wizard, select a template `menu:JME3[Basic Game (with Gradle)]` or `menu:JME3[Basic Game (with Ant)]`.
  9. . Gradle is the recommended build system since 3.6 (although there may still be many references to Ant projects, and they still work fine).
  10. . Click next to specify a project name, and the path where to store your new project.
  11. . Click Finish. A skeleton application is created and opens in the Project Explorer.
  12. ** This basic jme3 application is based on the SimpleApplication class to allow an easy start with jme3.
  13. ** You can click the run button to run it: You will see a blue cube.
  14. === Project Structure
  15. image::jmonkeyplatform-docu-4.png[jmonkeyplatform-docu-4.png,width="421",height="298",align="center"]
  16. Let's have a look at the abstract project structure in the Project Explorer. (kbd:[Ctrl]+kbd:[1]).
  17. * *Project Assets node:* These directories have been created for you to store your games assets, such as fonts, materials, models, shaders, sounds, and textures. For a newly created project, these directories are empty.
  18. * *Source Packages node:* This is where you manage your packages and classes. For a newly created project, it contains one package and one class, `Main.java`. Double click `Main.java` to open it in the editor.
  19. * *Libraries node:* An overview of all libraries on your game's classpath. The classpath is already set-up for the jme3 framework (including LWJGL, Bullet, Nifty +++<abbr title="Graphical User Interface">GUI</abbr>+++, etc).
  20. === Directory Structure
  21. Now let's have a look at the project's file structure in the File Explorer (kbd:[Ctrl]+kbd:[2]). This explorer shows the physical directory structure on your hard drive.
  22. * *assets* – This directory corresponds to the Project Assets node. It is needed for the assetManager.
  23. +
  24. This is the recommended internal structure:
  25. ** `assets/Interface`
  26. ** `assets/MatDefs`
  27. ** `assets/Materials`
  28. ** `assets/Models`
  29. ** `assets/Scenes`
  30. ** `assets/Shaders`
  31. ** `assets/Sounds`
  32. ** `assets/Textures`
  33. * *src* – This directory corresponds to the Source Packages node. Your sources code goes here.
  34. * *nbproject* – (Ant only) This is meta data used by the jMonkeyEngine SDK (don't edit).
  35. * *build.xml* – (Ant only) This is an Ant build script that is hooked up to the clean/build/run/test actions in the jMonkeyEngine SDK. It loads a default build script, and allows you to further customize the build process. The Ant script also assures that you are able to clean/build/run/test your application outside of the jMonkeyEngine SDK – e.g. from the command line.
  36. * *build.gradle* – (Gradle only) This is the gradle build script that will build your app.
  37. * *settings.gradle* – (Gradle only) This contains some properties of your project, like the name, and asset folder.
  38. * *build* – This directory contains the compiled classes. (Will be generated by the jMonkeyEngine SDK when you build the project.)
  39. * *dist* – This directory contains the executable JAR files. (Will be generated by the jMonkeyEngine SDK when you build the project.)
  40. * *test* – The jMonkeyEngine SDK will store JUnit tests here if you create any. (Optional.)
  41. === Project Configuration
  42. [RMB] select the project and from the menu open the project `Properties`.
  43. * In the `Run` section:
  44. ** Specify the main class of your project. (Pressing kbd:[F6] runs this main class.)
  45. ** You can optionally configure JVM options and command line parameters. In most cases, set the `-Xms VMOption [NUMBER] m` for the memory usage.
  46. *** For example (-Xms500m).
  47. *** see link:http://performance.netbeans.org/howto/jvmswitches/[http://performance.netbeans.org/howto/jvmswitches/].
  48. * In the Application section:
  49. ** Specify the game title (by default the game will be named `BasicGame`).
  50. ** Specify the vendor name (your name), a short description, your project's homepage, and a splash screen.
  51. === Clean, Build and Run Cycle
  52. image::jmonkeyplatform-docu-5.png[jmonkeyplatform-docu-5.png,width="421",height="298",align="center"]
  53. [IMPORTANT]
  54. ====
  55. Pressing *kbd:[F6] builds & runs* the _main_ class of the _main project_. If there are several classes, or several projects, you have to specify which one you want kbd:[F6] to run. btn:[RMB] select a project and choose `Set As Main Project`, then btn:[RMB] select the project again and choose `menu:Properties[Run]` and choose a Main Class.
  56. To build and run the main() of _any file that is open in the editor_, press kbd:[Shift]+kbd:[F6]!
  57. ====
  58. * btn:[RMB] select the project and use the context-menu to clean all generated classes and JARs.
  59. * btn:[RMB] select individual files with a main method to build and run them. (kbd:[Shift]+kbd:[F6])
  60. * Press the btn:[Run] button (green arrow in the toolbar) to build and run the project. (kbd:[F6])
  61. *More than one project open?* The toolbar buttons and the F-keys are bound to the main project, which is shown in bold in the Project Explorer. btn:[RMB] select a project and select `Set As Main Project` to make it respond to the toolbar buttons and F-keys.
  62. *Worried About Proprietary Lock-in?* You are never locked into the jMonkeyEngine SDK: At any time, you can change into your project directory on the command line, and clean, build, and run your project, using non-proprietary Apache Ant commands:
  63. [source]
  64. ----
  65. ant clean; ant jar; ant run;
  66. ----
  67. == Development Process
  68. * *Creating new files and packages:* Select the Source Packages node (or any of its subnodes), and press kbd:[Ctrl]+kbd:[N] (`menu:File[New File]`): Use the `New File` wizard to create new Java classes, Java packages, Java beans, Swing forms, JUnit files, j3m Materials, j3o scenes, j3f filters, and many more.
  69. * *Editing files:* Open the Projects Explorer and double-click a Java file from the Source Packages to open it in the Editor. The xref:code_editor.adoc[jMonkeyEngine SDK Code Editor] assists you in many ways, including syntactic and semantic code coloring, code completion, and javadoc.
  70. * *Adding Assets:*
  71. ** You can xref:model_loader_and_viewer.adoc[import models, scenes, and materials] as assets into your project.
  72. ** To add sound files and images, use your operating system's file explorer and copy the files into your project's asset directory.
  73. * *ToDo List:* The tasks window automatically lists all lines containing errors and warnings, and all lines that you have marked with the comment keywords
  74. +
  75. [source,html]
  76. ----
  77. FIXME
  78. ----
  79. , @todo, or TODO.
  80. * *Integrated tools:* xref:debugging_profiling_testing.adoc[Debugging, Testing, Profiling].
  81. === Adding external jar libraries
  82. You may want to use external Java libraries in your jME project, for example content generators or artificial intelligence implementations.
  83. ==== Gradle based projects:
  84. For gradle projects, you usually don't download a .jar beforehand. Instead, you speficy the library as a dependency, and gradle will download it.
  85. * Open `Build Scripts/build.gradle`.
  86. * Find `dependencies`.
  87. * Add the library as a classpath. You can usually find the definition at link:https://mvnrepository.com[Maven Central], if it's a common java library.
  88. More info: link:https://docs.gradle.org/current/userguide/declaring_dependencies.html[https://docs.gradle.org/current/userguide/declaring_dependencies.html]
  89. ==== Ant based projects:
  90. Add the library to the global library list:
  91. * Select menu:Tools[Libraries] in the main menu.
  92. * Click "`New Library`", enter a name for the library, and press btn:[OK].
  93. * In the "`Classpath`" tab, press "`Add JAR/Folder`" and select the jar file(s) needed for the library.
  94. * (Optional) In the "`JavaDoc`" tab, press "`Add ZIP/Folder`" and select the javadoc for the library, as zip file or folder.
  95. * (Optional) In the "`Sources`" tab you can select a folder or jar file containing the source files of the library.
  96. * Press btn:[OK].
  97. Add the library to a project:
  98. * btn:[RMB] select your project and select "`Properties`".
  99. * Select "`Libraries`" on the left and then press "`Add Library`".
  100. * Select the library from the list and press btn:[OK].
  101. That's it, your project can now use the external library. If you also linked the javadoc and sources, the SDK will assist you with javadoc popups, code completion (kbd:[Ctrl]+kbd:[Space]) and source navigation (kbd:[Ctrl]+btn:[LMB] ).
  102. === Application Deployment
  103. * You can xref:application_deployment.adoc[deploy] your game as desktop application (JAR), browser applet, WebStart (JNLP), or on the Android platform.
  104. == Running Sample Projects
  105. The SDK contains xref:sample_code.adoc[Sample Code] (read more).
  106. Open the Source Packages node of the JmeTests project.
  107. * btn:[RMB] select the `JME3Tests` project and choose Run. +
  108. Choose samples from the TestChooser and try out the included demos.
  109. * Browse a demo's source code in the SDK's Project window to learn how a feature is implemented and used.
  110. * Feel free to modify the code samples and experiment! If you break something, you can always recreate the packaged samples from the `JME3 Tests` template.