blob: b9fa95958058314761bfe24aa4583152bda66481 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= NetBeans Platform Runtime Container Tutorial
:jbake-type: platform_tutorial
:jbake-tags: tutorials
:jbake-status: published
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:icons: font
:experimental:
:description: NetBeans Platform Runtime Container Tutorial - Apache NetBeans
:keywords: Apache NetBeans Platform, Platform Tutorials, NetBeans Platform Runtime Container Tutorial
This tutorial covers the most fundamental concept in the NetBeans Platformthe runtime container. The runtime container is the execution environment for the modules that define a NetBeans Platform application. It consists of 6 modules provided by the NetBeans Platform. In this tutorial, we will look at these 6 modules, and use them in a very simple modular application.
Before going further, you can watch this video series, which covers the same material as the rest of this tutorial: link:nbm-10-top-apis.html[Top 10 NetBeans APIs]
NOTE: This document uses NetBeans Platform 7.1 and NetBeans IDE 7.1. If you are using an earlier version, see link:../70/nbm-runtime-container.html[the previous version of this document].
== Introduction to the Runtime Container
The "NetBeans runtime container" is the collective name for these NetBeans Platform modules:
image::images/runtime-container_maven-minimal-nb-dep-graph.png[]
Brief overview of each of these 6 modules:
* Startup (org-netbeans-core-startup)—Provides the main method of your application, as well as all the code needed for starting it up.
* Bootstrap (org-netbeans-bootstratp)—Enables the runtime container to understand what a module is and how to load and compose them into one application.
* Filesystem API (org-openide-filesystems)—Gives your application a virtual filesystem.
* Module System API (org-openide-modules)—Gives you access to the lifecycle of the modules in your application.
* Lookup API (org-openide-util-lookup)—Provides a generic communication mechanism for inter-modular interaction.
* Utilities API (org-openide-util)—Includes several utility classes shared between the other modules in the runtime container.
== Setting up the Runtime Container
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 havethe 6 modules that make up the runtime container. Once we have created an application that consists of nothing more than these 6 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.
[start=1]
1. Go to File > New Project. In the New Project dialog, choose NetBeans Modules > NetBeans Platform Application:
image::https://platform.netbeans.org/images/tutorials/htmleditor/new-nb-app-wiz-65.png[]
Click Next.
[start=2]
1. Name your application 'Hello World'. Click Finish.
[start=3]
1. 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.
[start=4]
1. In addition to the runtime container, many other modules are included. Exclude them now. Make sure that ONLY the 6 modules that make up the runtime container are included.
Run the application and notice that the application successfully executes.
== Loading a New Module into the Runtime Container
In this section, we add one new module to the NetBeans runtime container. The new module will do nothing special. The only reason for adding it will be so that you can see that it will be an equal partner to the other modules in your application. You will have 7 modules instead of the 6 that you already have, you will also have your custom module.
Next, we will influence the module's lifecycle. When it is loaded into the runtime container, we will use one of the module's lifecycle methods to send a 'Hello World' message to the Output window.
[start=1]
1. Right-click the application's Modules node and choose 'Add New...'. Click Next.
[start=2]
1. Give your module a project name and a code name base. Click Finish. You now have a new module.
[start=3]
1. Right-click the module, choose New > Other, and then choose Module Development > Installer/Activator. Click Next and then complete the wizard. You now have a new class that extends 'ModuleInstall', which is from the Module System API.
[start=4]
1. Add a new 'System.out.println' message in the 'restored' method of the Installer class.
Run the application again and notice the 'Hello World' message in the application's output. One place where you can see the application's output is in the IDE's Output window.
link:http://netbeans.apache.org/community/mailing-lists.html[Send Us Your Feedback]
== Next Steps
For the next steps in the "NetBeans Platform Fundamentals" series, see:
* link:nbm-selection-1.html[NetBeans Selection Management Tutorial IUsing a TopComponent's Lookup]
* link:nbm-10-top-apis.html[Top 10 NetBeans APIs]
* link:http://dvbcentral.sourceforge.net/netbeans-runtime.html[NetBeans Runtime Container Manifesto]
* link:http://blogs.oracle.com/geertjan/entry/mavenized_netbeans_platform_runtime_container[Mavenized NetBeans Platform Runtime Container]