| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <title>Platform Runtime Container Tutorial for the NetBeans Platform</title> |
| <link rel="stylesheet" type="text/css" href="https://netbeans.org/netbeans.css"/> |
| <meta name="AUDIENCE" content="NBUSER"/> |
| <meta name="TYPE" content="ARTICLE"/> |
| <meta name="EXPIRES" content="N"/> |
| <meta name="developer" content="tboudreau@netbeans.org"/> |
| <meta name="indexed" content="y"/> |
| <meta name="description" |
| content="A short guide to the NetBeans runtime container."/> |
| <!-- Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Oracle and/or its affiliates. All rights reserved. --> |
| <!-- Use is subject to license terms.--> |
| </head> |
| |
| <body> |
| |
| <h1>NetBeans Platform Runtime Container Tutorial</h1> |
| |
| <p>This tutorial covers the most fundamental concept in the NetBeans Platform—the runtime |
| container. The runtime container is the execution environment for the modules that define |
| a NetBeans Platform application. It consists of six modules provided by the NetBeans Platform. |
| In this tutorial, we will look at these six modules, and use them in a very simple modular |
| application.</p> |
| |
| <p>Before going further, you can watch this video series, which covers |
| the same material as the |
| rest of this tutorial: <a href="nbm-10-top-apis.html">Top 10 NetBeans APIs</a></p> |
| |
| <p><strong class="notes">Note: </strong>This document uses NetBeans Platform 8.0 and |
| NetBeans IDE 8.0. If you |
| are using an earlier version, see <a href="74/nbm-runtime-container.html">the previous version |
| of this document</a>.</p> |
| |
| <p><b>Contents</b></p> |
| |
| <p><img src="../images/articles/80/netbeans-stamp.png" class="stamp" width="114" height="114" alt="Content on this page applies to NetBeans IDE 8.0" title="Content on this page applies to NetBeans IDE 8.0"/></p> |
| <ul class="toc"> |
| <li><a href="#intro">Introduction to the Runtime Container</a></li> |
| <li><a href="#setup">Setting up the Runtime Container</a></li> |
| <li><a href="#add">Loading a New Module into the Runtime Container</a></li> |
| </ul> |
| |
| <p><b>To follow this tutorial, you need the software and resources listed in the following table.</b></p> |
| |
| <table> |
| <tbody> |
| <tr> |
| <th class="tblheader" scope="col">Software or Resource</th> |
| <th class="tblheader" scope="col">Version Required</th> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="https://netbeans.org/downloads/index.html">NetBeans IDE</a></td> |
| <td class="tbltd1">version 8.0 or above</td> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="http://java.sun.com/javase/downloads/index.jsp">Java Developer Kit (JDK)</a></td> |
| <td class="tbltd1">version 7 or above</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p class="tips">For troubleshooting purposes, you are welcome to download the <a href="http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/8.0/tutorials/container">completed tutorial source code</a>.</p> |
| |
| <h2 class="tutorial"><a name="intro"></a>Introduction to the Runtime Container</h2> |
| |
| <p>The "NetBeans runtime container" is the collective name for these |
| NetBeans Platform modules:</p> |
| |
| <p><img alt="diagram" src="../images/tutorials/runtime-container/container80.png"/></p> |
| |
| <p>Brief overview of each of these six modules:</p> |
| |
| <ul> |
| <li>Startup (org-netbeans-core-startup)—Provides the main method of your application, as well |
| as all the code needed for starting it up.</li> |
| <li>Bootstrap (org-netbeans-bootstratp)—Enables the runtime container to understand what |
| a module is and how to load and compose them into one application.</li> |
| <li>Filesystem API (org-openide-filesystems)—Gives your application a virtual filesystem.</li> |
| <li>Module System API (org-openide-modules)—Gives |
| you access to the lifecycle of |
| the modules in your application.</li> |
| <li>Lookup API (org-openide-util-lookup)—Provides a generic communication mechanism |
| for inter-modular interaction.</li> |
| <li>Utilities API (org-openide-util)—Includes several utility classes shared |
| between the other modules in the runtime container.</li> |
| </ul> |
| |
| <h2 class="tutorial"><a name="setup"></a>Setting up the Runtime Container</h2> |
| |
| <p>In this section, we will create an absolutely minimal NetBeans Platform application. |
| It will consist of only those modules that every NetBeans Platform application must |
| have—the six modules that make up the runtime container. Once we have created |
| an application that consists of nothing more than these six modules, we will run it. |
| There will be no specific output from this application. However, it will build and |
| run successfully because all the fundamental requirements of a NetBeans Platform |
| application will have been met.</p> |
| |
| <div class="indent"> |
| |
| <ol> |
| <li><p>Go to File > New Project. In the New Project dialog, choose |
| NetBeans Modules > NetBeans Platform Application:</p><br/> |
| <p><img alt="creating a new project" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-1.png"/></p> |
| <p>Click Next.</p></li> |
| <li>Name your application 'HelloWorld' and specify where to store it:<br/><br/> |
| <p><img alt="set the name" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-2.png"/></p> Click Finish. You now |
| have your first NetBeans Platform application:<br/><br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-3.png"/></p></li> |
| <li>Right-click the main project node in the Projects window, |
| choose Properties, and go to the Libraries tab. There you can |
| see all the modules that are part of this application:<br/><br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-4.png"/></p> |
| <br/><p class="notes"><b>Note:</b> Notice that the template you used in step 1 above preselected several modules for you. Also |
| notice that the preselected modules all come from the "platform" cluster.</p> |
| <p>In addition to the six modules making up the runtime container, many other modules are |
| included. We are going to exclude them in the next step because the purpose of this |
| tutorial is to create a minimal NetBeans Platform application, that is, |
| one that contains nothing more than the runtime container.</p> |
| </li> |
| <li>Click the checkbox next to "platform". Now all modules are unselected, that is, there |
| are now no modules in the application. Next, scroll down the list, find "Startup", |
| and click the corresponding checkbox, as shown below: |
| <br/><br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-5.png"/></p> |
| <br/> |
| <p>Click the Resolve button, because the Startup module depends on code found |
| in five other modules, that is, the other modules making up the runtime |
| container. Now you should see that the Resolve button disappears, together |
| with the warning messages:</p> |
| <br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-6.png"/></p> |
| <br/> |
| <p>Scroll up and down the list and notice that ONLY the six modules that make |
| up the runtime container are included.</p></li> |
| </ol> |
| |
| </div> |
| |
| <p>You now have a minimal NetBeans Platform application. It does not contain a user interface. It |
| has six modules that provide the low level plumbing mandatory in any NetBeans Platform |
| application.</p> |
| |
| <p>Right-click the application and choose Run. The application successfully executes |
| but doesn't do or display anything special yet.</p> |
| |
| <h2 class="tutorial"><a name="add"></a>Loading a New Module into the Runtime Container</h2> |
| |
| <p>In this section, we add one custom module to the NetBeans runtime container. The custom |
| module will do nothing special; it will only print a message to System.out. The only reason for adding the custom module will be so that you |
| can see that it will be an equal partner to the existing six modules in your application. |
| At the end of this section, you will have seven modules instead of the six that you |
| already have, that is, you will have included your own custom module.</p> |
| |
| <div class="indent"> |
| |
| <ol> |
| |
| <li><p>Right-click the application's Modules node and choose 'Add New...'.</p> |
| <br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-7.png"/></p> |
| </li> |
| |
| <li><p>Give your module a project name, such as 'HelloModule' and specify |
| a location to store the module:</p> |
| |
| <br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-8.png"/></p> |
| <br/> |
| <p>Click Next.</p> |
| </li> |
| |
| <li>Specify a code name base, which is a unique string |
| that identifies the module: |
| |
| <br/><br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-9.png"/></p> |
| <br/> |
| <p>Click Finish. You now have a new module:</p> |
| <br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-91.png"/></p> |
| </li> |
| |
| <li>Right-click the module, choose New > Other, and then choose |
| Module Development > Installer/Activator: |
| <br/><br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-92.png"/></p> |
| <p>Click Next.</p> |
| </li> |
| <li>Click Finish below to complete the wizard: |
| <br/><br/> |
| <p><img alt="project structure" src="../images/tutorials/runtime-container/maven-minimal-nb-dep-graph-72-93.png"/></p> |
| <p>You now have a new |
| class that extends the NetBeans ModuleInstall class, which is from the Module |
| System API.</p></li> |
| |
| <li>Add a new 'System.out.println' message in the 'restored' method of |
| the Installer class, as shown in the highlighted line below: |
| <pre class="examplecode">package org.mycompany.hello; |
| |
| import org.openide.modules.ModuleInstall; |
| |
| public class Installer extends ModuleInstall { |
| |
| @Override |
| public void restored() { |
| <b>System.out.println("hello world!");</b> |
| } |
| |
| }</pre> |
| </li> |
| |
| |
| |
| <li>Run the application again and notice the 'Hello World' message in the application's |
| output, in the Output window, which can be opened from the Window menu. The end of |
| the stack trace, which includes the 'hello world' message, should be something like this: |
| |
| <pre class="examplecode">org.mycompany.hello.netbeans: |
| Generating Auto Update information for org.mycompany.hello |
| run: |
| run.run: |
| hello world! |
| ------------------------------------------------------------------------------- |
| >Log Session: Friday, June 27, 2014 5:05:32 PM CEST |
| >System Info: |
| Product Version = HelloWorld-Ant nbms-and-javadoc-1540-on-20140411 |
| Operating System = Linux version 3.11.0-23-generic running on i386 |
| Java; VM; Vendor = 1.8.0; Java HotSpot(TM) Server VM 25.0-b70; Oracle Corporation |
| Runtime = Java(TM) SE Runtime Environment 1.8.0-b132 |
| Java Home = /home/geertjan/jdk1.8.0/jre |
| System Locale; Encoding = en_US (helloworld_ant); UTF-8 |
| Home Directory = /home/geertjan |
| Current Directory = /home/geertjan/NetBeansProjects/api-samples/versions/8.0/tutorials/container/HelloWorld-Ant |
| User Directory = /home/geertjan/NetBeansProjects/api-samples/versions/8.0/tutorials/container/HelloWorld-Ant/build/testuserdir |
| Cache Directory = /home/geertjan/NetBeansProjects/api-samples/versions/8.0/tutorials/container/HelloWorld-Ant/build/testuserdir/var/cache |
| Installation = /home/geertjan/NetBeansProjects/api-samples/versions/8.0/tutorials/container/HelloWorld-Ant/build/cluster |
| /home/geertjan/netbeans-8.0/platform |
| /home/geertjan/netbeans-8.0/platform |
| Boot & Ext. Classpath = /home/geertjan/jdk1.8.0/jre/lib/resources.jar:/home/geertjan/jdk1.8.0/jre/lib/rt.jar:/home/geertjan/jdk1.8.0/jre/lib/sunrsasign.jar:/home/geertjan/jdk1.8.0/jre/lib/jsse.jar:/home/geertjan/jdk1.8.0/jre/lib/jce.jar:/home/geertjan/jdk1.8.0/jre/lib/charsets.jar:/home/geertjan/jdk1.8.0/jre/lib/jfr.jar:/home/geertjan/jdk1.8.0/jre/classes:/home/geertjan/jdk1.8.0/jre/lib/ext/nashorn.jar:/home/geertjan/jdk1.8.0/jre/lib/ext/dnsns.jar:/home/geertjan/jdk1.8.0/jre/lib/ext/sunec.jar:/home/geertjan/jdk1.8.0/jre/lib/ext/localedata.jar:/home/geertjan/jdk1.8.0/jre/lib/ext/sunjce_provider.jar:/home/geertjan/jdk1.8.0/jre/lib/ext/jfxrt.jar:/home/geertjan/jdk1.8.0/jre/lib/ext/sunpkcs11.jar:/home/geertjan/jdk1.8.0/jre/lib/ext/zipfs.jar:/home/geertjan/jdk1.8.0/jre/lib/ext/cldrdata.jar:/usr/java/packages/lib/ext/jpcap.jar |
| Application Classpath = /home/geertjan/netbeans-8.0/platform/lib/boot.jar:/home/geertjan/netbeans-8.0/platform/lib/org-openide-modules.jar:/home/geertjan/netbeans-8.0/platform/lib/org-openide-util-lookup.jar:/home/geertjan/netbeans-8.0/platform/lib/org-openide-util.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/boot_ja.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/boot_pt_BR.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/boot_ru.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/boot_zh_CN.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-modules_ja.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-modules_pt_BR.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-modules_ru.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-modules_zh_CN.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-util-lookup_ja.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-util-lookup_pt_BR.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-util-lookup_ru.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-util-lookup_zh_CN.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-util_ja.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-util_pt_BR.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-util_ru.jar:/home/geertjan/netbeans-8.0/platform/lib/locale/org-openide-util_zh_CN.jar:/home/geertjan/jdk1.8.0/lib/dt.jar:/home/geertjan/jdk1.8.0/lib/tools.jar |
| Startup Classpath = /home/geertjan/netbeans-8.0/platform/core/core.jar:/home/geertjan/netbeans-8.0/platform/core/org-openide-filesystems.jar:/home/geertjan/netbeans-8.0/platform/core/locale/core_ru.jar:/home/geertjan/netbeans-8.0/platform/core/locale/core_zh_CN.jar:/home/geertjan/netbeans-8.0/platform/core/locale/org-openide-filesystems_ru.jar:/home/geertjan/netbeans-8.0/platform/core/locale/org-openide-filesystems_ja.jar:/home/geertjan/netbeans-8.0/platform/core/locale/org-openide-filesystems_zh_CN.jar:/home/geertjan/netbeans-8.0/platform/core/locale/org-openide-filesystems_pt_BR.jar:/home/geertjan/netbeans-8.0/platform/core/locale/core_ja.jar:/home/geertjan/netbeans-8.0/platform/core/locale/core_pt_BR.jar:/home/geertjan/NetBeansProjects/api-samples/versions/8.0/tutorials/container/HelloWorld-Ant/build/cluster/core/locale/core_helloworld_ant.jar |
| ------------------------------------------------------------------------------- |
| INFO [org.netbeans.core.startup.NbEvents]: Turning on modules: |
| org.openide.util.lookup [8.24.1 201403101706] |
| org.openide.util [8.37.1 201403101706] |
| org.openide.modules [7.42.1 201403101706] |
| org.openide.filesystems [8.10.1 201403101706] |
| org.netbeans.bootstrap/1 [2.67.1 201403101706] |
| org.netbeans.core.startup/1 [1.54 nbms-and-javadoc-1540-on-20140411] |
| org.mycompany.hello [1.0 140627] |
| BUILD SUCCESSFUL (total time: 18 seconds)</pre></li> |
| |
| </ol> |
| |
| </div> |
| |
| <p>In this tutorial, you have used the least amount of NetBeans Platform modules that any NetBeans Platform application |
| requires, that is, the NetBeans runtime container, consisting of six modules. You added a custom module, that is, |
| a module that you created yourself. The custom module printed a message into the Output window.</p> |
| |
| <p>Notice that you did not need to create a main method because the NetBeans runtime container contains one already. |
| The "module" concept was also predefined in the NetBeans runtime container. Other features of the NetBeans |
| runtime container will be introduced as you take the next steps outlined below.</p> |
| |
| <div class="feedback-box"><a href="https://netbeans.org/about/contact_form.html?to=3&subject=Feedback:%20NetBeans%20Runtime%20Container%20Tutorial%208.0">Send Us Your Feedback</a></div> |
| |
| <h2>Next Steps</h2> |
| <p>To continue your journey on the NetBeans Platform, see:</p> |
| <ul> |
| <li><a href="https://netbeans.org/features/platform/features.html">NetBeans Platform Features</a></li> |
| <li><a href="nbm-quick-start.html">NetBeans Platform Quick Start</a></li> |
| <li><a href="nbm-selection-1.html">NetBeans Selection Management Tutorial I—Using a TopComponent's Lookup</a></li> |
| <li><a href="nbm-10-top-apis.html">Top 10 NetBeans APIs</a></li> |
| <!-- li><a href="http://wiki.apidesign.org/wiki/NetBeans_Runtime_Container">NetBeans Runtime Container Manifesto</a></li> |
| <li><a href="http://blogs.oracle.com/geertjan/entry/mavenized_netbeans_platform_runtime_container">Mavenized NetBeans Platform Runtime Container</a></li> |
| --> |
| </ul> |
| |
| </body> |
| |
| </html> |