LDSTechForumProjects

Getting Started with NetBeans IDE

NetBeans provides sophisticated Maven integration so that any Maven project is a first-class citizen and automatically recognized by the IDE without the need to import the project or keep it in sync with IDE-specific meta-data. NetBeans natively uses Maven for all of your project configuration and building needs. As a result, NetBeans is compatible with any Maven plugins, allowing you to extend much of the IDE's project-specific functionality directly through Maven.

What follows are instructions and tips for installing and using the NetBeans IDE for Java Stack project development.

Pre-installation

Before installing NetBeans IDE, you may need to perform one or more of the following installations first:

  1. (Required) Install Java SDK 6 or Later. JDK 8 is recommended for running the IDE, but if you are using Stack 3 or earlier, you will also need to configure the IDE to use JDK 7 for compiling and running your project. Go to "Tools > Java Platforms" to add JDK 7 to your IDE.)
    • Go to http://www.oracle.com/technetwork/java/javase/downloads/index.html
    • Download the latest version of the Java SE JDK for your operating system. Be sure to choose 32 or 64 bit based on your operating system. (64 bit recommended)
    • Install the JDK to the default location (e.g. C:\Program Files\Java\jdk1.7.0_xx) or choose another location if you prefer. (NetBeans has no problem with spaces in the path.)
      • Linux users: You may prefer the *.tar.gz or *.bin packages to the *.rpm or *.deb packages if you prefer to install the JDK in the location of your choice.
  2. (Optional) Install Maven.
    • NetBeans comes bundled with Maven 3.0.4 (<netbeans_dir>/java/maven, but you may optionally supply the IDE a separate Maven installation if your project requires an older version.
    • To download Maven, go to http://maven.apache.org/download.html
    • Unzip the archive to a location on your hard drive
    • If you need to use Maven from the command-line, you will want to set the following environment variables:
      • (Required) Set JAVA_HOME to the location of your JDK home directory (e.g. C:\Program Files\Java\jdk1.7.0_xx)
      • (Optional) Set M2_HOME to the folder where you installed Maven (e.g. C:\apache-maven-3.0.4).
      • (Recommended) Add %M2_HOME%\bin to your PATH environment variable.

Installation

  1. Install the NetBeans IDE
    • Go to http://netbeans.org/downloads/index.html
    • Choose the Java EE bundle. This contains most everything you need for Java web development.
    • Once downloaded, run the installer and follow the instructions.
      • Important! You may safely skip (uncheck) the installation of GlassFish and Tomcat. Java Stack projects don't use GlassFish, and they are capable of creating their own specially configured Tomcat instances.

Post Installation

Project Workspace

Unlike Eclipse-based IDEs, NetBeans does not require you to define a workspace. All of your NetBeans configuration settings are stored in the %USER_HOME%/.netbeans folder. On Windows operating systems (as of NetBeans 7.2 and later) these settings are stored in the %appdata%\NetBeans folder

Important! For users on the Windows 7 Church Desktop, the folder where you keep your project code and store your local Maven repository can have significant impact on system performance. Sophos Anti-virus is configured to scan jar files whenever they are downloaded, created, or accessed. During a normal workday, this can cause system CPU usage to max out at 100% for significant amounts of time, resulting in poor performance generally, and especially for the IDE. However, Sophos Anti-virus is configured to skip on-access scanning of files under the C:\workspaces folder. In order to prevent Sophos Anti-virus from unnecessarily scanning your jar files and dependencies, it is recommended that you keep your project code and your local Maven repository under that folder.

To place your local Maven repository under C:\workspaces, you must edit the file %USER_HOME%\.m2\settings.xml (or create it, if it does not exist):

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
    <localRepository>C:/workspaces/maven/repository</localRepository>
</settings>

Performance Tips

(Recommended)

Due to the nature of Java Stack enterprise applications, you may find improved performance by configuring NetBeans to use more memory and concurrent garbage collection. (The following settings were determined to be optimal for the Java Stack by analyzing the IDE's performance with the jvisualvm tool included with the JDK.)

  1. In the NetBeans installation directory (e.g. C:\Program Files\NetBeans 8.0), edit the etc\netbeans.conf startup configuration. (You may need to edit the permissions on this file to grant your user the rights to modify it.)
    • Edit the netbeans_default_options parameter as follows:
      • You should give the IDE at least 384 MB of heap memory (larger if you keep several projects open at a time). To increase the heap memory available to the IDE, replace the -J-Xms32m JVM parameter with the following:
        -J-Xms384m
      • The IDE needs at least 128 MB of perm gen space (256 MB recommended). To increase the IDE's permanent generation space (memory used for classes and static instances), replace the -J-XX:PermSize=32m JVM parameter with the following:
        -J-XX:PermSize=128m
      • (Windows only) Add the following parameters to improve garbage collection performance:
        -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled
    • When you're finished, the modified line should look something like this:
      netbeans_default_options="-J-client -J-Xss2m -J-Xms384m -J-XX:PermSize=128m-J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled -J-Djava.net.preferIPv4Stack=true"
      
    • (Optional) On Linux, you may prefer to use the Nimbus look-and-feel (particularly on Ubuntu/Unity in which the GTK+ look-and-feel occasionally doesn't render well). In this case, you can add the following additional argument to netbeans_default_options property:
      --laf Nimbus


Configuring a Different Version of Maven

(Optional)

If you need to use a version of Maven other than the one bundled with NetBeans, you can point NetBeans to a separate Maven installation:

  1. From the menu, select Tools -> Options and click "Java". Then select the "Maven" tab.
    Netbeans-setup-maven.png

  2. Under "Maven Home", browse to the location of your local Maven installation.
  3. (Optional) Check the box "Skip Tests for any build executions not directly related to testing"
  4. Leave all other settings as they are. Click OK.


Configuring Maven to Use the Correct JDK Platform

(Optional)

If you need to have Maven build against a separate JDK than the default, do the following:

  1. Add the JDK installation to the IDE(Tools > Java Platforms)
    • Make sure you have also added {JAVA_HOME}/src.zip under source location.
    • Add {JAVA_HOME}/docs/api under the javadoc location. Note that some installations will set this value as just {JAVA_HOME}/docs which is the wrong path. (Alternatively, the IDE may just give it a web location, which will work fine, although API information for code completion may pop up more slowly.)
  2. Create or modify the %USER_HOME%\.m2\settings.xml file to add the profile defined below:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
    <profiles>
        <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <netbeans.hint.jdkPlatform>JDK_${jdkVersion}</netbeans.hint.jdkPlatform>
            </properties>
        </profile>
    </profiles>
</settings>


Adding Custom Maven Actions

(Optional)

You can define custom or project-specific goals that will show up in the project node's context menu.

  • To create custom project-specific goals:
    1. Right-click the project node
    2. Select Custom > Goal...
    3. Enter the goal names and any configuration properties
  • To create custom global goal definitions for maven tasks that you use frequently across your projects:
    1. From the menu, select Tools -> Options
    2. Choose the Miscellaneous option group
    3. Open the Maven tab
    4. Click the button Edit Custom Global Goal Definitions
    5. Enter the goal names and any configuration properties


Useful Custom Global Goal Definitions

Below are some useful custom goal definitions for speeding up maven builds or for debugging maven itself (e.g. for custom maven plugins). The goals and properties below can be added through Tools > Options > Java > Maven > "Edit Global Custom Goal Definitions...". Or, if you prefer, you can simply create or modify the file below with the following definitions:

  • %USER_HOME%\.netbeans\8.0\config\Projects\org-netbeans-modules-maven\nbactions.xml
    or %APP_DATA%\NetBeans\8.0\config\Projects\org-netbeans-modules-maven\nbactions.xml
<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <!-- A custom action for a minimal build that skips DB
         migration, tests, and JavaDoc generation -->
    <action>
        <actionName>CUSTOM-Clean and Build (Minimal)</actionName>
        <displayName>Clean and Build (Minimal)</displayName>
        <goals>
            <goal>clean</goal>
            <goal>install</goal>
        </goals>
        <properties>
            <skipTests>true</skipTests>
            <skipITs>true</skipITs>
            <source.skip>true</source.skip>
            <maven.javadoc.skip>true</maven.javadoc.skip>
            <db.skipDBTool>true</db.skipDBTool>
        </properties>
    </action>
    <!-- A custom action for a minimal build that debugs the Maven build process itself
         (Useful only when developing custom Maven plugins) -->
    <action>
        <actionName>CUSTOM-Clean and Build (Minimal, Debug Maven)</actionName>
        <displayName>Clean and Build (Minimal, Debug Maven)</displayName>
        <goals>
            <goal>clean</goal>
            <goal>install</goal>
        </goals>
        <properties>
            <jpda.listen>maven</jpda.listen>
            <skipTests>true</skipTests>
            <skipITs>true</skipITs>
            <source.skip>true</source.skip>
            <maven.javadoc.skip>true</maven.javadoc.skip>
            <db.skipDBTool>true</db.skipDBTool>
        </properties>
    </action>
    <!-- A custom action for a full build that debugs the Maven build process itself
         (Useful only when developing custom Maven plugins) -->
    <action>
        <actionName>CUSTOM-Clean and Build (Full, Debug Maven)</actionName>
        <displayName>Clean and Build (Full, Debug Maven)</displayName>
        <goals>
            <goal>clean</goal>
            <goal>install</goal>
        </goals>
        <properties>
            <jpda.listen>maven</jpda.listen>
        </properties>
    </action>
</actions>


Creating an LDSTech Tomcat Installation

(For Stack 3.x Projects)

  • To facilitate creating an LDSTech Tomcat server installation, copy the following nbactions.xml to your *-deploy project (or on the *-deploy project node context menu, select Custom > Goal...), then execute the goal, create a new Tomcat server in the IDE that points to the configured Tomcat instance.
<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <action>
        <actionName>CUSTOM-Create LDSTech Server</actionName>
        <displayName>Create LDSTech Server</displayName>
        <goals>
            <goal>stack-tomcat:config</goal>
        </goals>
        <properties>
            <skipDeploy>false</skipDeploy>
            <tomcatClean>true</tomcatClean>
            <tomcatConfigureManager>true</tomcatConfigureManager>
            <!-- Optional: Provide a custom location for the LDSTech Tomcat server -->
            <tomcatTargetDir>
                ${user.home}/.ldstech/${project.groupId}/${project.version}/${project.artifactId}/tomcat
            </tomcatTargetDir>
        </properties>
    </action>
</actions>
  • Right-click on the tomcat-deployable project and select Custom / Create LDSTech Server from the context menu. This will create your LDSTech Tomcat Server.
  • Note the location in the Maven log where the server was installed and, in the IDE, create a new Apache Tomcat server that points to the LDSTech Tomcat installation you just created.
  • Any changes to the tomcat-deployable project will necessitate re-running the Custom / Create LDSTech Server context menu action.


Running the WAM emulator

(For Stack 3.x projects)

To facilitate starting up the WAM emulator, copy the following nbactions.xml to your parent project. (Or to have the IDE create this file for you, right-click on the parent project node and select Custom > Goal..., then enter the settings below.)

<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <action>
        <actionName>CUSTOM-Run WAM Emulator</actionName>
        <displayName>Run WAM Emulator</displayName>
        <goals>
            <goal>stack-wam:run</goal>
        </goals>
        <properties>
            <wamSkip>false</wamSkip>
        </properties>
    </action>
</actions>


Running Sonar

(For local code analysis)

To run your build with a local installation of Sonar, add the following profile to %USER_HOME%\.m2\settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
    <profiles>
        <!-- ... other profiles ... -->
        <profile>
            <id>sonar</id>
            <activation>
                <property>
                    <name>sonar.skip</name>
                    <value>false</value>
                </property>
            </activation>
            <repositories>
                <repository>
                    <id>lds-plugin</id>
                    <name>LDS Plugin Repo</name>
                    <url>http://code.lds.org/nexus/content/groups/plugin-repo</url>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                </repository>
            </repositories>
        </profile>
    </profiles>
</settings>


Additional Tips

**See Robert Thornton on the Java Stack Team for any additional help or tips on maximizing your productivity using NetBeans.

This page was last modified on 29 July 2014, at 10:58.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.