This guide shall help you trough the process of creating a new LibGDX project to use in Netbeans 8.0. It will focus on the Desktop and Android versions of the game engine. IOS and Web can still be opened in eclipse (all project folders will still be able to) but this guide won't go over these two. You should be able to keep total compatibility with Eclipse. One or multiple programmer(s) could use the same project with both Eclipse and Netbeans. This guide doesn't need Eclipse at any moment, you don't need to download or install it if you don't want to.

The project name we'll be using today is Project123. Don't forget to replace this with your project name not only in Netbeans, but also where scripts are used.

Prepare Project

Create a directory named Project123 that we will use as the root of our project. Download and unpack the LibGDX files in Project123/libgdx. You will then be able to run Project123/libgdx/gdx-setup-ui.jar to create the libgdx project. Use the following settings:
  • Name: Project123
  • Package: com.me.project123
  • Game class: Project123
  • Destination: Select your root Project123 created earlier.

Desktop Project

Create new Java project in Netbeans.

File -> New Project then Java -> Java Application

Use the following settings:
  • Use your project name and append -Netbeans to create the netbeans project.
  • Select the root project folder Project123 as the location.
  • Uncheck "Create Main Class"

Next, right-click your Project123-Netbeans and select Properties.On the Sources pages, enter the following settings:
  • Add the Project123/Project123/src folder and enter the src label.
  • Add the Project123/Project123-Desktop/src folder under the src-Desktop label.
On the Libraries page. Use the following:
  • Under the Compile tag. Click Add Jar/Folder and select all ".jar" in the Project123/libgdx directory, except gdx-backend-gwt, gdx-setup-ui, gdx-backend-robovm.
  • Use the Relative Path folder setting.

You should now be able to run your desktop project. If you run it now using the default config, you will probably get an error that the file data/libgdx.jpg is missing. To fix that, either copy the data folder from Project123-android/asset to your Project123-Netbeans project or create a symlink:
            //Windows :  
            mklink /d path/to/Project123-android/asset/data path/to/Project123-Netbeans

            ln -s  path/to/Project123-android/asset/data path/to/Project123-Netbeans

Android Project

First, make sure that you have installed the android sdk with the Netbeans plugin nbandroid. Once installed, restart Netbeans to make sure every config and plugins has loaded correctly. Because if it's not loaded correctly, you won't see the Android icon over the project's folder icon.

Let's now open our android project: File -> Open Project -> Select the Project123-android folder.

Now, in order to run the android project, Netbeans needs a compiled version of the default project. In order to do that automatically, we will add a script that will copy the required libs into the android project. Open up the build.xml file from the Project123-Netbeans folder.

Add the following just before the </project> tag and after the --> closing comment tag:

    <target name="-post-jar">
        <copy toDir="${output.dir}/../../Project123-android/libs">
          <fileset file="dist/${ant.project.name}.jar" />
          <fileset file="dist/lib/gdx.jar" />

Now once this is done, Right-Click on your Project123-Netbeans project (not android) and select Clean and Build. This shall compile the .jar needed for android and will copy it in the right directory. You will need to do that each time you change something in the main project and want to run on android. 

After this, you should be able to run the android project. You will then be able to choose a virtual android device or a external device plugged by USB.

For reference, here is a screenshot of my view in Netbeans Project tab:

I hope this guide helped you. Let me know if you have problems, questions or comments. Thank you for reading!

Reference link:

comments powered by Disqus