Maven NBM Quickstart 6.8

This document demonstrates how to create a NetBeans Platform Application using Maven and NetBeans IDE 6.8. This document is based on NetBeans Platform Quick Start

The steps in the document currently do not work after the first section. Many of the problems encountered are discussed in Maven NBM Comments. Additional info about the plugin here: Netbeans Module plugin

The items that need to be resolved are the following:

  • Steps for updating to 6.8. Are the steps below correct? How can the splash screen be updated from 6.7?
  • Using lookup and annotations
  • How to build when a module has another module as a dependency. Currently the output for building with dependencies is the following:

Private classes referenced from module:
[ERROR]Project depends on packages not accessible at runtime in module...


Draft!!

Contents


Requirements for This tutorial

You need the following software:

  • NetBeans IDE 6.8

Prerequisites

This document assumes you have some basic knowledge of, or programming experience with, the following technologies:

  • Java Programming
  • NetBeans IDE

Before starting this tutorial you may want to familiarize yourself with the following documentation.

Creating the NetBeans Platform Application Project

In this section you use the New Project wizard to create a NetBeans Platform Application from a Maven archetype. In this section you will also modify the sample platform module that is generated by the New Project wizard.

Creating the Maven Platform Application Project

To create the platform application:

  1. Choose File > New Project (Ctrl-Shift-N). Select Maven Project from the Maven category. Click Next.
  2. Select Maven NetBeans Platform Application Archetype. Click Next.
  3. Type MavenPlatformWordApp for the Project Name and set the project location. Click Finish.

File:Maven-nbm-newprojectwizard1.png

When you click Finish, by default the IDE creates the following Maven project types.

  • NetBeans Platform Application
    This project is a container project for the Platform application and lists the modules to include and the location of the project's repositories. This project does not contain any sources. The IDE generates the modules containing the sources and resources in this folder.
  • NetBeans Platform based application
    This project specifies the artifacts (sources) needed for compiling the application. This project specifies the details of the required dependencies (IDE artifacts, module artifacts) in the pom.xml file.
  • sample NetBeans Module
    This project is created by default as an example of a module of a platform application. You can remove this project.
  • Platform application branding resources
    This project contains the resources used for branding the application.

When you create the project, you will see that the NetBeans Platform based application project is badged because some dependencies are unavailable. If you look at the file pom.xml (POM) for the project you can see that the sample module is listed as a dependency, but the artifact is not available until you build the sub-modules. For all Maven projects, the POM is located under the Project Files node.

File:Maven-nbm-projectswindow1.png

If the branding module is named <Badly formed Maven project> in the Projects window, right-click the project in the Projects window and choose Reload Project. See MavenMissingExtensionPluginError

If you look at the pom.xml file for the sample module you see that the project has the artifactId module1.

<parent>
      <groupId>com.mycompany</groupId>
      <artifactId>MavenPlatformWordApp</artifactId>
      <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>module1</artifactId>
  <packaging>nbm</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>MavenPlatformWordApp - sample NetBeans Module</name>

The sample module is a NetBeans module. To build a NetBeans module you need to use the nbm-maven-plugin. If you look at the POM for the sample module, you can see that the IDE automatically specified the plugin to use to build the project as a NetBeans module.

<plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>nbm-maven-plugin</artifactId>
</plugin>

For more information on the NetBeans plugin, see the


If you look at the pom.xml file for the NetBeans Platform Application, you can see that module1 is listed as one of the modules in the application.

<modules>
   <module>module1</module>
   <module>branding</module>
   <module>application</module>
</modules>

If you look at the pom.xml file for the NetBeans Platform based application, you can see that the module1 artifact is listed as a required dependency for compiling the application.

<dependency>
   <groupId>com.mycompany</groupId>
   <artifactId>module1</artifactId>
   <version>1.0-SNAPSHOT</version>
   <type>nbm</type>
</dependency>

Specifying the Name of the NetBeans Platform Application

When you create the Platform application from the Platform application archetype, the default name for the application is foo.

In this exercise you will update the POM file to specify the name of the application.

  1. Open the POM for the NetBeans Platform Application.
  2. Modify the <brandingToken> element to change the name to MavenPlatformWordApp and save your changes.
<properties>
    <netbeans.version>RELEASE67</netbeans.version>
    <brandingToken>MavenPlatformWordApp</brandingToken>
</properties>

Setting this results in the following exception. The brandingToken element only accepts lowercase letters. How do i set the app name?

java.lang.IllegalArgumentException: Malformed branding token: MavenPlatformWordApp

       at org.openide.util.NbBundle.setBranding(NbBundle.java:128)
       at org.netbeans.core.startup.CLIOptions.cli(CLIOptions.java:206)
       at org.netbeans.core.startup.CLIOptions.cli(CLIOptions.java:92)
       at org.netbeans.CLIHandler.notifyHandlers(CLIHandler.java:224)
       at org.netbeans.CLIHandler.initialize(CLIHandler.java:471)
       at org.netbeans.CLIHandler.initialize(CLIHandler.java:343)
       at org.netbeans.MainImpl.execute(MainImpl.java:197)
       at org.netbeans.MainImpl.main(MainImpl.java:78)
       at org.netbeans.Main.main(Main.java:75)

Modifying the Sample Module

In this section you will modify the sample module to add a window component and a button and text area.

Adding a Window Component to the sample Module

In this exercise you will use a wizard to add a Window Component to the sample module.

  1. Right-click MavenPlatformWordApp - sample NetBeans Module in the Projects window and choose New > Other to open the New File dialog.
  2. Select Window Component in the Module Development category. Click Next.
  3. Select output in the Window Position dropdown list. Click Next.
  4. Type Text in the Class Name Prefix field. Click Finish.
    The wizard displays a list of the files that will be created and the files that will be modified.


When you click Finish, in the Projects window you can see that the IDE generated the classes TextAction.java and TextTopComponent.java in com.mycompany.wordengine under Source Packages. The IDE also generated additional resource files in com.mycompany.wordengine under Other Sources. In this exercise you will only edit TextTopComponent.java so you can close the other files.

You can view the structure of the project in the Files window. To compile a Maven project, only Java files can be located under Source Packages (src/main/java directory in the Files window). Non-Java files (e.g., XML files) need to be located under Other Sources (src/main/resources directory in the Files window).


Modifying the Window Component

You will now add the text area and button elements to the window component by performing the following steps.

  1. Click the Design tab of TextTopComponent.java in the editor.
  2. Drag and drop a button and a text area from the Palette onto the window.
  3. Right-click the text area and choose Change Variable Name, and then type text as the name. You will use the name when accessing the component from your code.
  4. Set the text of the button to "Filter!"
  5. Double-click the button to open the event handler method for the button in the source code editor. The method is created automatically when you double-click the button element.
  6. Modify the body of the method to the following code.
    You can use the code completion in the editor to help you type the code.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
   String s = text.getText();
   s = s.toUpperCase();
   text.setText(s);
}

File:Maven-nbm-textopcomponent.png


Testing the Application

  1. Right-click the project node of the MavenPlatformWordApp NetBeans Platform based application and choose Build with Dependencies.
  2. Right-click the project node of the MavenPlatformWordApp NetBeans Platform based application and choose Run.

When you Run the application, the IDE launches the NetBeans Platform 6.7 application. To test the application, perform the following steps:

  1. Choose Window > Text from the main menu or the platform application.
  2. Type some characters in the text area. Click Filter!

When you click Filter!, the characters that you typed are changed to upper case and displayed in the text area.

Updating the Platform Version and Splash Image

The default archetype for 6.8 specifies 6.7 as platform version. This section needed until platform archetypes are updated to 6.8. Currently the archetype specifies RELEASE67 and platform10.


Updating the Platform Version in NetBeans Platform Application

In this exercise you will update the POM file to specify the NetBeans 6.8 version of the artifacts.

  1. Open the POM for the NetBeans Platform Application.
  2. Modify the <netbeans.version> element to change the version to RELEASE68 and save your changes.
<netbeans.version>RELEASE68</netbeans.version>
    <brandingToken>MavenPlatformWordApp</brandingToken>
</properties>

Updating the Dependencies in NetBeans Platform based application

In this exercise you will update the POM file to change the artifact for the IDE cluster to platform11.

  1. Open the POM for the NetBeans Platform based application.
  2. Modify the <artifactId> element to change the version to platform11 and save your changes.
<dependency>
  <groupId>org.netbeans.cluster</groupId>
  <artifactId>platform11</artifactId>
  <version>${netbeans.version}</version>
  <type>pom</type>
</dependency>

Replacing the Splash Screen

In this exercise you will update the replace the default splash image. By default the branding module generated by the IDE contains an image that is displayed when the platform application starts. You can replace this with a different image by performing the following steps.

  1. Locate the default splash image for the application (splash.gif) that is located in the following directory.

In the Projects window: Other Sources > nbm-branding > core > core.jar > org > netbeans > core > startup

In the Files window: src > main > nbm-branding > core > core.jar > org > netbeans > core > startup

  1. Replace the default image with an image named splash.gif.

For example, you can copy the image below to the startup directory. File:Splash.gif


Testing the Application

  1. Right-click the project node of the MavenPlatformWordApp NetBeans Platform based application and choose Build with Dependencies.
  2. Right-click the project node of the MavenPlatformWordApp NetBeans Platform based application and choose Run.

This seems to work, but the splash screen still says 6.7 but the product version is 200912041610.

Adding the TextFilter Module to the Platform Application

In this exercise you will create the module TextFilter for the platform application and add the module as a dependency to the application.

Creating the TextFilter Platform Module

In this exercise you will create a new module for the Platform application. After you create the module you need to add the module as a dependency of the application.

To create the module:

  1. Choose File > New Project (Ctrl-Shift-N). Select Maven Project from the Maven category. Click Next.
  2. Select Maven NetBeans Module Archetype. Click Next.
  3. Type TextFilter for the Project Name.
  4. Click Browse to set the Project Location and locate the MavenPlatformWordApp directory. Click Finish.

File:Maven-nbm-moduleprojectlocation.png

When you click Finish, the IDE creates the module and opens the module project NetBeans Module TextFilter in the Projects window.

Adding the TextFilter Module as a Dependency of MavenPlatformWordApp

In this exercise you add the TextFilter module as a dependency of the the MavenPlatformWordApp application.

  1. Right-click the Libraries node of the MavenPlatformWordApp - NetBeans Platform based application project and choose Add Dependency.
  2. Click the Open Projects tab in the Add Dependency dialog.
  3. Select the NetBeans Module TextFilter module. Click OK.

File:Maven-nbm-add-dependency-dialog-openprojects.png

When you click OK, the IDE adds the module as a dependency of the project. If you expand the Libraries node, you can see that the module is added to the list of dependencies.

Sometimes this does not work. The module is not added to the POM and you have to edit the POM in the editor to add the dependency. But the module is added to the list for the platform application project.

If you open the POM for MavenPlatformWordApp - NetBeans Platform based application, you can see that the IDE added the following lines inside the dependencies element in the POM.

<dependency>
   <groupId>${project.groupId}</groupId>
   <artifactId>TextFilter</artifactId>
   <version>${project.version}</version>
</dependency>

The IDE also modifies the POM of the MavenPlatformWordApp - NetBeans Platform Application project to add the TextFilter module to the list of modules that are included in the application.

<modules>
    <module>module1</module>
    <module>branding</module>
    <module>application</module>
    <module>TextFilter</module>
</modules>

Adding an Interface to the TextFilter Module

In this exercise you will add an interface.

  1. Right-click the "TextFilter" module and choose New > Java Interface.
  2. Type TextFilter as the Class Name.
  3. Select com.mycompany.textfilter in the Package dropdown list. Click Finish.
  4. Modify the class to add the following code. Save your changes.
package com.mycompany.textfilter;

public interface TextFilter {
    String process(String s);
}

The option to specify the API Versioning is not available in the Properties window. Is there a workaround for this?

Making the TextFilter Module Public

In this exercise you will make the contents of the com.mycompany source package public so that other modules can access the methods. To declare the package as public, you will modify the configuration element of nbm-maven-plugin in the POM to add the package to the list of packages that are exported as public by the plugin.


For more information, see nbm-maven-plugin manifest


  1. Open the POM of the TextFilter module.
  2. Modify the configuration element of the nbm-maven-plugin artifact to add the following. Save your changes.
<publicPackages>
   <publicPackage>com.mycompany.*</publicPackage>
</publicPackages>

The POM entry should now contain the following:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>nbm-maven-plugin</artifactId>
    <version>3.1</version>
    <extensions>true</extensions>
    <configuration>
                    <publicPackages>
                        <publicPackage>com.mycompany.*</publicPackage>
                    </publicPackages>
      <descriptor>src/main/nbm/module.xml</descriptor>
    </configuration>
</plugin>

The option to specify the API Versioning is not available in the Properties window. Does modifying the plugin elements accomplish the same thing?


Modifying the MavenPlatformWordApp application

In this exercise you will modify the event handler in the Text window component to load implementations of TextFilter.

  1. Add the TextFilter module as a dependency of the sample module. The Add Dependency dialog does not work here either. Maybe it only works if the project is already compiled.
  2. Open the TextTopComponent in the editor.
  3. Modify the button handler method to add the following:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String s = text.getText();
        TextFilter filter = Lookup.getDefault().lookup(TextFilter.class);
        s = s.toUpperCase();
        text.setText(s);
    }

Save your changes.

Testing the Application

  1. Right-click the project node of the MavenPlatformWordApp NetBeans Platform based application and choose Build with Dependencies.
  2. Right-click the project node of the MavenPlatformWordApp NetBeans Platform based application and choose Run.

Building and running do not work. The application does not build, specifically it looks like the MyFilter module does not build and there is the following error in the output:

NBM Plugin generates manifest Private classes referenced from module: [com.mycompany.textfilter.TextFilter] [ERROR]Project depends on packages not accessible at runtime in module com.mycompany:TextFilter:jar:1.0-SNAPSHOT


Troubleshooting

I can add the modules and add dependencies to modules, but I am unable to get the application to compile after adding one module as a dependency of another module.

The MyFilter module will not build. So the platform application will not compile if i use Build with Dependencies. I see the error "Private classes referenced from module" and the build fails.

Is there a workaround for this?

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