Geertjan's Blog

  • July 22, 2010

Bye NetBeans IDE (Part 3)

Geertjan Wielenga
Product Manager
Now that we know how to create a new NetBeans Platform application without using NetBeans IDE (part 1, part 2), let's add a new module to that application. Firstly, we create a new module structure providing no more than the absolute bare essentials. Secondly, we register that module with the application. Thirdly, we add some basic code to the module so that we can provide a feature to the application.

Creating the Module Structure

  1. Module Root Folder. Create a new folder within the application's main folder. Name it, for example, MyModule.

  2. Module Project Folder. Copy the application project folder into the module root folder. In other words, you will use the application project folder as the starting point for your module project folder.

  3. Suite Properties. In the module project folder, delete the 'platform.properties' file. Instead of a 'platform.properties' file, you need a 'suite.properties' file, which will point to the application that owns the module. It should have this content:
  4. Build Script. In the module root folder, create a 'build.xml' file, with this content:
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="org.demo.mymodule" default="netbeans" basedir=".">
    <description>Builds, tests, and runs the project org.demo.mymodule.</description>
    <import file="nbproject/build-impl.xml"/>
  5. Manifest. In the module root folder, create a 'manifest.mf' file, with this content:
    Manifest-Version: 1.0
    OpenIDE-Module: org.demo.mymodule
    OpenIDE-Module-Specification-Version: 1.0
  6. Build-Impl Script. In the module project folder, create a file named 'build-impl.xml', with this content:
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="org.demo.mymodule-impl" basedir="..">
    <property file="nbproject/suite.properties"/>
    <property file="${suite.dir}/nbproject/platform.properties"/>
    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
    <attribute name="name"/>
    <attribute name="value"/>
    <property name="@{name}" value="${@{value}}"/>
    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
    <attribute name="property"/>
    <attribute name="value"/>
    <property name="@{property}" value="@{value}"/>
    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
    <import file="${harness.dir}/build.xml"/>
  7. Project Properties. In the module project folder, change the file named 'project.properties', to this content:
    javac.compilerargs=-Xlint -Xlint:-serial
  8. Project Configuration. In the module project folder, change the file named 'project.xml', to this content:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://www.netbeans.org/ns/project/1">
    <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
  9. Main Package. In the module root folder, create folder structure 'src/org/demo/mymodule'. The content will be added later, we simply need to have the main package.

Registering the Module

Now that you have a module structure, lets register it in the application.

  1. Project Properties. In the application project folder, create a 'project.properties' file for the application, add this:
  2. Platform Properties. Change the 'platform.properties' file of the application to this:
  3. Try It Out. Run the application and you'll see the module is loaded, by looking in the output:

Adding a Feature to the Module

We'll use the module to provide a new menu item to the application.

  1. Add an Action. In the "org.demo.mymodule" package, add a class named 'HelloWorldAction', with this content:
    package org.demo.mymodule;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JOptionPane;
    public final class HelloWorldAction implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(null, "hello...");
  2. Add a Layer. In the main package, create a new 'layer.xml' file that registers an Action item and a Menu item:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
    <folder name="Actions">
    <folder name="Window">
    <file name="org-demo-mymodule-HelloWorldAction.instance">
    <attr name="delegate" newvalue="org.demo.mymodule.HelloWorldAction"/>
    <attr name="displayName" bundlevalue="org.demo.mymodule.Bundle#CTL_HelloWorldAction"/>
    <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
    <folder name="Menu">
    <folder name="Window">
    <file name="HelloWorldAction.shadow">
    <attr name="originalFile" stringvalue="Actions/Window/org-demo-mymodule-HelloWorldAction.instance"/>
  3. Add a Bundle. In the main package, add a file named 'Bundle.properties' with this content:
    CTL_HelloWorldAction=Hello World
  4. Register the Layer and Bundle. Register the latter two files in the 'manifest.mf', which is in your module root folder:
    OpenIDE-Module-Layer: org/demo/mymodule/layer.xml
    OpenIDE-Module-Localizing-Bundle: org/demo/mymodule/Bundle.properties

Run the application. It starts up and there's a new menu item under the Window menu.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.