project_creation.adoc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 the template `menu:JME3[Basic Game]`.
  9. . Click next to specify a project name, and the path where to store your new project.
  10. . Click Finish. A skeleton application is created and opens in the Project Explorer.
  11. ** This basic jme3 application is based on the SimpleApplication class to allow an easy start with jme3.
  12. ** You can click the run button to run it: You will see a blue cube.
  13. === Project Structure
  14. image::jmonkeyplatform-docu-4.png[jmonkeyplatform-docu-4.png,width="421",height="298",align="center"]
  15. Let's have a look at the abstract project structure in the Project Explorer. (kbd:[Ctrl]+kbd:[1]).
  16. * *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.
  17. * *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.
  18. * *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).
  19. === Directory Structure
  20. 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.
  21. * *assets* – This directory corresponds to the Project Assets node. It is needed for the assetManager.
  22. +
  23. This is the recommended internal structure:
  24. ** `assets/Interface`
  25. ** `assets/MatDefs`
  26. ** `assets/Materials`
  27. ** `assets/Models`
  28. ** `assets/Scenes`
  29. ** `assets/Shaders`
  30. ** `assets/Sounds`
  31. ** `assets/Textures`
  32. * *src* – This directory corresponds to the Source Packages node. Your sources code goes here.
  33. * *nbproject* – This is meta data used by the jMonkeyEngine SDK (don't edit).
  34. * *build.xml* – 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.
  35. * *build* – This directory contains the compiled classes. (Will be generated by the jMonkeyEngine SDK when you build the project.)
  36. * *dist* – This directory contains the executable JAR files. (Will be generated by the jMonkeyEngine SDK when you build the project.)
  37. * *test* – The jMonkeyEngine SDK will store JUnit tests here if you create any. (Optional.)
  38. === Project Configuration
  39. [RMB] select the project and from the menu open the project `Properties`.
  40. * In the `Run` section:
  41. ** Specify the main class of your project. (Pressing kbd:[F6] runs this main class.)
  42. ** You can optionally configure JVM options and command line parameters. In most cases, set the `-Xms VMOption [NUMBER] m` for the memory usage.
  43. *** For example (-Xms500m).
  44. *** see link:http://performance.netbeans.org/howto/jvmswitches/[http://performance.netbeans.org/howto/jvmswitches/].
  45. * In the Application section:
  46. ** Specify the game title (by default the game will be named `BasicGame`).
  47. ** Specify the vendor name (your name), a short description, your project's homepage, and a splash screen.
  48. === Clean, Build and Run Cycle
  49. image::jmonkeyplatform-docu-5.png[jmonkeyplatform-docu-5.png,width="421",height="298",align="center"]
  50. [IMPORTANT]
  51. ====
  52. 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.
  53. To build and run the main() of _any file that is open in the editor_, press kbd:[Shift]+kbd:[F6]!
  54. ====
  55. * btn:[RMB] select the project and use the context-menu to clean all generated classes and JARs.
  56. * btn:[RMB] select individual files with a main method to build and run them. (kbd:[Shift]+kbd:[F6])
  57. * Press the btn:[Run] button (green arrow in the toolbar) to build and run the project. (kbd:[F6])
  58. *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.
  59. *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:
  60. [source]
  61. ----
  62. ant clean; ant jar; ant run;
  63. ----
  64. == Development Process
  65. * *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.
  66. * *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.
  67. * *Adding Assets:*
  68. ** You can xref:model_loader_and_viewer.adoc[import models, scenes, and materials] as assets into your project.
  69. ** To add sound files and images, use your operating system's file explorer and copy the files into your project's asset directory.
  70. * *ToDo List:* The tasks window automatically lists all lines containing errors and warnings, and all lines that you have marked with the comment keywords
  71. +
  72. [source,html]
  73. ----
  74. FIXME
  75. ----
  76. , @todo, or TODO.
  77. * *Integrated tools:* xref:debugging_profiling_testing.adoc[Debugging, Testing, Profiling].
  78. === Adding external jar libraries
  79. You may want to use external Java libraries in your jME project, for example content generators or artificial intelligence implementations.
  80. Add the library to the global library list:
  81. * Select menu:Tools[Libraries] in the main menu.
  82. * Click "`New Library`", enter a name for the library, and press btn:[OK].
  83. * In the "`Classpath`" tab, press "`Add JAR/Folder`" and select the jar file(s) needed for the library.
  84. * (Optional) In the "`JavaDoc`" tab, press "`Add ZIP/Folder`" and select the javadoc for the library, as zip file or folder.
  85. * (Optional) In the "`Sources`" tab you can select a folder or jar file containing the source files of the library.
  86. * Press btn:[OK].
  87. Add the library to a project:
  88. * btn:[RMB] select your project and select "`Properties`".
  89. * Select "`Libraries`" on the left and then press "`Add Library`".
  90. * Select the library from the list and press btn:[OK].
  91. 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] ).
  92. === Application Deployment
  93. * You can xref:application_deployment.adoc[deploy] your game as desktop application (JAR), browser applet, WebStart (JNLP), or on the Android platform.
  94. == Running Sample Projects
  95. The SDK contains xref:sample_code.adoc[Sample Code] (read more).
  96. Open the Source Packages node of the JmeTests project.
  97. * btn:[RMB] select the `JME3Tests` project and choose Run. +
  98. Choose samples from the TestChooser and try out the included demos.
  99. * Browse a demo's source code in the SDK's Project window to learn how a feature is implemented and used.
  100. * 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.