NetBeans Platform Maven Command Line Tutorial

This document demonstrates how to create a
NetBeans Platform application and module from a command line prompt using the Maven build framework.
To create this application you do not need to install or use the NetBeans IDE.
You will need to create and edit some files, but you can use a simple text editor.
However, an IDE can be very helpful when performing tasks such as editing the POM and managing dependencies.

In this tutorial you will see that after you install Maven, you can specify goals and parameters
and execute Maven goals from the command line prompt to create and build projects.
The IDE performs the same task, but provides an interface that simplifies the task of specifying
the parameters for creating projects.

Creating the NetBeans Platform Application

In this exercise you will execute the Maven goal generate from the command line to generate
a new NetBeans Platform application from an archetype in the codehaus.org repository.
In the command you will specify the parameters that will be used when Maven generates the application.

You can see that the command specifies the archetype that Maven will use to create
the NetBeans Platform application (netbeans-platform-app-archetype).
The command also specifies the location of the repository for the archetype (http://repository.codehaus.org/)
and the version (1.19) and GroupId (org.codehaus.mojo.archetypes) of the archetype.

When you run the command, Maven will automatically retrieve the archetype and create the project according to
the details specified in the command (artifact id, version, package).

Note. When you use NetBeans IDE to create a
Mavenized NetBeans Platform application,
the IDE executes a Maven goal with the same parameters.

For more information about the plugin that is used to generate the artifacts,
see the documentation on the nbm-maven-plugin.

When you run the command, you will see output similar to the following in the terminal window.

If you look in the root directory mavenPlatformApp that was created,
you can see that the new project contains a pom.xml file and a directory for each of the default sub-modules of the archetype: application and branding.

If you open pom.xml for mavenPlatformApp in an editor, you will see that the
POM specifies all the details required for building the application:

If you look at the <properties> element, you can see that the version of the NetBeans Platform is
specified as RELEASE72. In the POM of your sub-modules, you can specify ${netbeans.version} as the version
and the module will use the version specified in the parent POM project.
The enables you to easily update the NetBeans Platform version for all the project's sub-modules.

Installing and Running the NetBeans Platform Application

In this exercise you will run the Maven install goal from the command line to build the application and copy
the artifacts in your local repository.
The NetBeans Platform application is a multi-module application.
You will use the reactor mechanism in Maven to build the application project and the project's dependencies.
After you build the application you will execute the run-platform goal to launch the application.

Navigate to the mavenPlatformApp directory and type the following command to
build the project:

mvn install

The above command will take some time to complete. When the command
completes, you will see the following:

After the command above completes, navigate to the application directory and type the following command to launch the application.

mvn nbm:run-platform

When you run the nbm-maven-plugin with the run-platform goal, as done above, Maven will
launch your NetBeans Platform application:

Browse through the menus to see what your new application consists of. Open
some windows, undock some of them, and you will have something that looks like this:

You have now successfully created and launched your NetBeans Platform application.
The default branding elements are located in the branding sub-module that was generated according to the archetype.
The NetBeans IDE provides tools and wizards that can help you to modify the branding elements.

In the next section you will create a new module for the application.

Creating a NetBeans Module from an Archetype

You will now create a new module that is named mavenPlatformModuleA in the mavenPlatformApp directory.
In the same way that you created the NetBeans Platform application,
you will run a Maven command from the command line and use the module archetype nbm-archetype.

After you create the module, you will use a text editor to create a simple class in the module.
You will then build the module to install the module in the local repository.

Navigate to the mavenPlatformApp directory in the command line
terminal and run the following command:

If you look at the contents of the mavenPlatformApp directory, you will see that the directory
contains a new directory that is named mavenPlatformModuleA.
The new directory contains a src directory and pom.xml.
The file bundle.properties is generated in the
resources/com/mycompany/mavenplatformmodulea directory:

In the next step you will create a class in the
java/com/mycompany/mavenplatformmodulea directory.

Edit the new module's pom.xml to make the following changes (in bold) to add a dependency on
the modules you are referring to in the code above.

Building the NetBeans Platform Application With the New NetBeans Module

You are now almost ready to launch the NetBeans Platform application with the new module installed.
You first need to make sure that the new module is specified as a module of the parent POM project.
You can then repeat the steps to build and launch the application.

Open the pom.xml in the mavenPlatformApp directory in a text editor.

Confirm that the new module is specified in the list of modules that are included with the application.

Navigate to the application directory and type the following command to launch the application.

mvn nbm:run-platform

When you run the command, Maven will launch the application with the new module.

You have now successfully added a new module to the application and launched the application.
To confirm that the module was loaded when the application launched,
choose Window > Hello World from the main menu of the application to display the
greeting:

This tutorial demonstrated how you can use the Maven command line to create NetBeans
Platform applications.
For more examples on how to build NetBeans Platform applications and modules,
see the tutorials listed in the NetBeans Platform Learning Trail.

See Also

This document described
how to use the Maven build framework to create a new NetBeans Platform application without using NetBeans IDE.
For more information about creating and developing applications, see the following resources.