IJC Hello World Plugin


    Welcome to Instant JChem plugin development!

    Instant JChem installation and NetBeans IDE installation are covered in IJC Plugin Quick Start page. Having Instant JChem and NetBeans IDE installed and also having 'IJC Platform' set up in NetBeans IDE is prerequisite for this Hello World Plugin development.

    This tutorial will guide you through the process of Instant JChem plugin development and you will create your fist IJC plugin.


    Creating module suite

    The first step is to create NetBeans module suite. Open NetBeans IDE, use new project wizard from the main menu Files -> New Project...

    On the wizard's first page select NetBeans Modules category and Module Suite project and click Next button.

    The second page lets you enter the name of your module suite project, its location on the disk and most importantly the 'NetBeans Platform' that the project will be based on. We called our suite simply IJC-Extensions and let the IDE place it in the default location. We also selected IJC Platform as a 'NetBeans Platform' to use for our plugin development. It is important to select the platform that you set up earlier in IJC Plugin Quick Start.

    When the wizard finishes you should have the 'IJC-Extensions' module suite project ready for further development and visible in the IDE's 'Projects' explorer. As you can see the suite contains no modules and several configuration files. In the next step we are going to create a new plugin module and add it to the suite.

    Creating plugin module

    As for creating module suite projects the entry point for creating a module is the new project wizard. You can find it in the main menu File -> New Project... or click the symbol in the IDE's toolbar or simply press its shortcut Ctrl+Shift+N.

    When the 'New Project' wizard pops up select Module project from NetBeans Modules category and press Next button.

    In the next step please enter the name of your plugin module project. We called our project HelloWorldPlugin and let the IDE to create it in the default location. Also tell the wizard to add the new module to the IJC-Extensions module suite that we created before. When done press Next to proceed to the final step.

    In the last step you will enter the essential information about your plugin module - its code name base and display name. The code name base is simply a java package where your module's source code will be placed - enter org.myplugin.helloworld for Code Name Base. Complete the wizard and press Finish button.

    When the wizard creates 'HelloWorldPlugin' project you will see it in the IDE's 'Projects' explorer alongside the 'IJC-Extensions' module suite project. The 'HelloWorldPlugin' project will also appear under the 'IJC-Extensions' module suite's 'Modules' node to indicate that the module is part of the suite.


    NetBeans IDE's 'Projects' explorer showing our new 'HelloWorldPlugin' module project

    Coding "Hello World!"

    So far we have created a module suite and added new module to it. In order to test the module we will add some very basic functionality to it. We are going to create an action that will print "Hello World!" text and place it in the Instant JChem's main menu called 'Chemistry'.

    Right click the org.myplugin.helloworld package node in the 'Projects' explorer and in the popup menu select New -> Action. This will start a 'New Action' wizard that will help us generate all necessary files. On wizard's first page we have to choose the type of our new action. We want it to be a simple action, which is always enabled and can always be used. Choose Always Enabled and click Next.

    On the next page we will specify where in the menu the action will appear. In the 'Category' and 'Menu' select Chemistry. Let's select the last action in the 'Position' combobox and tick the 'Separator Before' checkbox. This will place our action at the bottom of Instant JChem's 'Chemistry' menu and separate it from the above menu items with a separator.

    After clicking next the last page is shown, which allows entering the action's java class name, display name, icon, etc. In order to keep things simple we will just enter the class name and display name and leave the other options as they are. Let's call our action's class HelloWorldAction and set its display name to Hello World!. The display name is a string that will be displayed in Instant JChem's menu when we run our plugin.

    When you finish the wizard and let it generate the source files you will see HelloWorldAction class open in the IDE's source code editor.


    Finally, we will add some code. In the source editor find actionPerformed method in HelloWorldAction class and add javax.swing.JOptionPane.showMessageDialog(null, "Hello World!"); to its body. In the 'Projects' explorer go to IJC-Extensions suite project node, right click it and in the popup menu choose Clean and Build.

    Launching the plugin

    In order to launch the plugin as part of Instant JChem you simply right click the 'IJC-Extensions' project node and choose Run, which will deploy the plugin and start Instant JChem. When started you should see Hello World! action in the main menu at the bottom of Chemistry.

    When you click the action popup message will appear:


    Well done! You have just successfully built and launched your first IJC plugin. In this tutorial you have learned:

    • What development tools you need for developing Instant JChem plugins

    • How to create a module suite and a plugin module

    • How to create a simple action and install it in Instant JChem's main menu

    • How to test Instant JChem with your new plugin

    For other IJC plugin development related tutorials please see their complete list here.