blob: be9b1c1de365929bac5132c6004d9d628867ed64 [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.
//
= DevFaqNonGuiPlatformApp
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqNonGuiPlatformApp
:description: Apache NetBeans wiki DevFaqNonGuiPlatformApp
:toc: left
:toc-title:
:syntax: true
== Can I create a console or server (non-GUI) app with the NetBeans Platform?
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. Note that this explains how to develop an application which is only ever meant to run headless, not how to develop a single application which can run in either GUI _or_ command line mode (which is described in the second half of this page).
This is done by simply starting with the NetBeans Platform and removing all but the most essential components. NetBeans architect link:http://www.apidesign.org/[Jaroslav Tulach] calls this subset of the NetBeans platform the "link:http://wiki.apidesign.org/wiki/NetBeans_Runtime_Container[runtime container]" and wrote an application which uses it to link:http://dvbcentral.sourceforge.net/[control his television].
Here are the steps for creating a runtime container application:
1. Create a new suite
2. Exclude all clusters from the suite
3. Re-enable the platform cluster, but disable all but the following modules:
* Bootstrap
* File System API
* Lookup API
* Module System API
* Startup
* Utilities API
[start=4]
. Add a new module to the suite
[start=5]
. Create and register a `ModuleInstall` class
[start=6]
. The `restored()` method is effectively your application's `main` method.
[start=7]
. You may optionally override the `close()` method of your `ModuleInstall` to clean up resources upon shutdown, but be sure then to call `LifecycleManager.getDefault().shutDown()`.
You will also need to suppress the splash screen by passing `--nosplash` argument when starting the app.
== How Can I Make My NetBeans Platform Run in GUI or Command-Line Mode?
If your application performs some repetitive task like engineering analysis and you have some users who prefer using the command line and some who don't, you may be asked to modify your application so that it can run in either the normal GUI mode or in batch processing mode from the command line.
The exact method for doing this will vary per application, but you will typically need to add a module to interpret some custom command-line arguments using the link:http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-sendopts/[Command Line Processing API]. Inside the process(Env env, Map<Option, String[]> map) method of your option processor, you'll invoke whatever code corresponds to the arguments the user specified (e.g. myapp --import path/to/file.txt might import some file).
Remember that you should not use System.out, System.err and System.in for the output, error and input streams in the options processor but instead get them from the Env object passed as a parameter to the process method.
When running a platform application which contains the Window System and other GUI modules, you will also need to specify --nosplash --nogui on the command line at startup to prevent the splash screen and window system from being displayed. You may also wish to set the netbeans.logger.console system property to true (e.g. specify -J-Dnetbeans.logger.console=true on the command line) so that you will see NetBeans' error messages on the console. It might also be a good idea to specify the plugin.manager.check.interval=NEVER system property to avoid checks for new plugins when running in command line mode.
Finally, note that prior to NetBeans 6.10, the current working directory available from the Env object was set to the directory of the application's installation, not the directory from which the command was executed. The consequence of this is that resolving relative file paths did not work as expected on Microsoft Windows systems, although it does work correctly on all versions of UNIX I tested. This has been resolved (link:http://netbeans.org/bugzilla/show_bug.cgi?id=189791[http://netbeans.org/bugzilla/show_bug.cgi?id=189791]), but the suggested workaround for affected versions of the platform is to introduce an additional batch file which invokes the NetBeans executable by passing in a Java system property that specifies the current (execution) directory.
<hr/>
Applies to: NetBeans 6.5 and later
=== Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from link:http://wiki.netbeans.org/DevFaqNonGuiPlatformApp[http://wiki.netbeans.org/DevFaqNonGuiPlatformApp] ,
that was last modified by NetBeans user Tomwheeler
on 2010-09-10T16:38:01Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.