I am a Principal Software Engineer at Object Computing, Inc. (OCI), and live in the St. Louis, Missouri, USA area. Although I know and regularly use several languages, I've predominantly been programming in Java for the last ten years. I first started using Linux in 1995 and have been a strong advocate of open source software ever since. Perhaps the best example of how I've been active in improving open source software has been my work with the NetBeans Platform. I was very skeptical about the platform at first, but I quickly came to realize that it was the best way to create Java desktop applications and so I set out to try and make it even better. Since 2005 I have written documentation, reported bugs, supplied patches, given presentations and answered questions on the development mailing lists. I won the NetBeans Community Award in 2006 and now serve on the NetBeans DreamTeam and NetBeans Governance Board. Tom has posted 4 posts at DZone. View Full User Profile

How to Create a Console/Server Application on the NetBeans Platform

  • submit to reddit

While most documentation explains the NetBeans Platform in terms of Java desktop applications, it is possible to build a non-GUI application on the NetBeans Platform. This might be useful, for example, when creating a platform-based application which will distribute computationally expensive work among a group of machines.

This is done by simply starting with the NetBeans Platform and removing all but the most essential components. NetBeans architect Jaroslav Tulach calls this subset of the NetBeans platform the "runtime container" and wrote an application which uses it to control his television.

Here are the steps for creating a runtime container application:

  1. Create the skeleton application. Click Ctrl-Shift-N to bring up the New Project dialog and then create a new NetBeans Platform Application:

    Click Next and give your application a name and location on disk:

    Click Finish and you have the starting point of your application:

  2. Specify the minimum required NetBeans Platform modules. Right-click the project node and choose Properties. In the Libraries tab, you'll notice that only the "platform" cluster (which is simply a set of related modules) is selected. Within that cluster, several modules have been included by default. These provide a minimal GUI application.

    We now need to exclude several of these to create a minimal non-GUI (i.e., a console application or a server application). In the end, you should ONLY have checkmarks next to the following 5 modules:

    • Bootstrap
    • File System API
    • Module System API
    • Startup
    • Utilities API

    The user interface for this step looks as follows:

  3. Create a new module in the application. Back in the New Project dialog (Ctrl-Shift-N), add a new module to the suite:

    Click Next and name your module, while making sure the module will be added to the application. I.e., click "Add to Module Suite", if it isn't selected automatically.

    Click Next and specify a unique name for the application, i.e., the Code Name Base. Also add a module display name. If you are going to need to register items in the layer file, specify a location for the layer file, otherwise create it later:

    When you click Finish, your application will have one new module, i.e., the one you just created, which is registered to be part of the application:

    Your application now consists of 6 modules:

    • Bootstrap
    • Demo Module
    • File System API
    • Module System API
    • Startup
    • Utilities API

  4. Create an entry point into the application. Now we will add a class that will effectively act as our "main class". Use the New File dialog to create and register a "ModuleInstall" class for this purpose:

    Click Next and note what will be created/updated:

    When you click Finish, you will have a new class called "Installer". The "restored()" method of the "ModuleInstall" class is effectively your application's main method. Here a "hello world" message has been added there:

    Note: You may optionally override the close() method of your "ModuleInstall" class to clean up resources upon shutdown.

  5. Disable the splash screen. Since you're creating a console app, you may want to supress the splash screen, by passing the --nosplash argument when starting the application, as shown in line 7 below of the application's project.properties file:

Now when you run the application, you will see your 'hello world' message in the console, proving that the starting point of your console/server application (i.e., a non-GUI application) is working successfully.

From http://wiki.netbeans.org/DevFaqNonGuiPlatformApp

fig-1.png67.83 KB
fig-2.png51.33 KB
fig-3.png21.27 KB
fig-4.png77.59 KB
fig-5.png61.75 KB
fig-6.png59.04 KB
fig-7.png46.98 KB
fig-8.png34.03 KB
fig-9.png88.75 KB
fig-10.png49.76 KB
fig-11.png72.28 KB
fig-12.png66.15 KB
Published at DZone with permission of its author, Tom Wheeler.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)