DocsMavenPlatformFromCommandLine

Creating a NetBeans Platform Application from Maven Archetypes

Please see the final version of this document Creating NetBeans Platform Applications from Maven Archetypes

Contents


Requirements for This tutorial

You need the following software:

  • Maven
  • JDK

Creating the NetBeans Platform Application

  1. Open a command line terminal.
  2. Confirm that Maven is correctly configured by typing the following command.
mvn -version

You will see details about the Maven installation similar to the following.

Apache Maven 2.2.0 (r788681; 2009-06-26 15:04:01+0200)
Java version: 1.6.0_20
Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.5.8" arch: "x86_64" Family: "mac"
  1. Navigate to the directory where you want to create the NetBeans Platform application.
  2. Type the following in the terminal to create a project named mavenPlatformApp:
mvn -DarchetypeVersion=1.5 -Darchetype.interactive=false -DgroupId=com.mycompany -DarchetypeArtifactId=netbeans-platform-app-archetype -DarchetypeRepository=http://repository.codehaus.org/ -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.codehaus.mojo.archetypes -Darchetype.repository=http://repository.codehaus.org/ -Dpackage=com.mycompany.mavenplatformapp -DartifactId=mavenPlatformApp --batch-mode org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate

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

Installing and Running the NetBeans Platform Application

  1. Navigate to the root directory of the mavenPlatformApp project and type the following command to build the project using the reactor plugin.
mvn --also-make --projects com.mycompany:application install
  1. Navigate to the application directory and type the following command to run the platform application.
mvn install nbm:run-platform

The platform application will launch.

Creating a Module from an Archetype

You will now create a new module that is named mavenPlatformModuleA in the root directory based on the module archetype.

  1. Navigate to the root directory and type the following command:
mvn -DarchetypeVersion=1.4 -Darchetype.interactive=false -DgroupId=com.mycompany -DarchetypeArtifactId=nbm-archetype -DarchetypeRepository=http://repository.codehaus.org/ -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.codehaus.mojo.archetypes -Darchetype.repository=http://repository.codehaus.org/  -Dpackage=com.mycompany.mavenplatformmodulea -DartifactId=mavenPlatformModuleA --batch-mode org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate

If you look at the contents of the new directory, you can see that the directory contains a src directory and that the layer.xml and bundle.properties files are created by the archetype in the resources directory.

  1. Create the following class HelloWorldAction.java in the com.mycompany.mavenplatformmodulea package.
package com.mycompany.mavenplatformmodulea;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

public class HelloWorldAction implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(null, "hello...");
    }

}
  1. Edit the layer.xml file to add the following:
<folder name="Actions">
        <folder name="Window">
            <file name="com-mycompany-mavenplatformmodulea-HelloWorldAction.instance">
                <attr name="delegate" newvalue="com.mycompany.mavenplatformmodulea.HelloWorldAction"/>
                <attr name="displayName" bundlevalue="com.mycompany.mavenplatformmodulea.Bundle#CTL_HelloWorldAction"/>
                <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
            </file>
        </folder>
    </folder>
    <folder name="Menu">
        <folder name="Window">
            <file name="HelloWorldAction.shadow">
                <attr name="originalFile" stringvalue="Actions/Window/com-mycompany-mavenplatformmodulea-HelloWorldAction.instance"/>
            </file>
        </folder>
    </folder>
  1. Edit the bundle.properties to add the following:
CTL_HelloWorldAction=Hello World
  1. Type the following command to build and install the module.
mvn install
  1. Edit the pom.xml of application to declare the mavenplatformmodulea module a dependency of the netbeans application.
<dependency>
            <groupId>com.mycompany</groupId>
            <artifactId>mavenPlatformModuleA</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
  1. Edit the pom.xml of the pom project to add the module.
<modules>
        <module>branding</module>
        <module>application</module>
    <module>mavenPlatformModuleA</module>
  </modules>
  1. Navigate to the root pom project and type the following command to build the project with dependencies using the reactor plugin:
mvn --also-make --projects com.mycompany:application install
  1. Navigate to the application directory and run the platform application by typing the following command.
mvn install nbm:run-platform
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo