Apache NetBeans Wiki Index

Note: These pages are being reviewed.

Installing things declaratively as opposed to programmatically

Long ago, in a galaxy far far away, most objects in NetBeans were created during startup. That works fine for a small application. It is disaster for a large application - with each new component in the system, startup time gets longer, garbage collections get more frequent and memory requirements rise.

Because of this, today, most of the APIs you will use to install things into the the IDE or a NetBeans Platform-based application involve a text entry of some sort, such as putting something in an XML file), or a plain-text file naming some classes in your JAR file’s META-INF/services directory — not running Java code. A well-behaved module should do nothing on startup.

The main ways to accomplish this goal are to use either the [http://bits.netbeans.org/dev/javadoc/org-openide-util-lookup/org/openide/util/lookup/ServiceProvider.html @ServiceProvider] annotation (which generates the aforementioned META-INF/services files at compile-time), or by registering files or objects in your module’s XML layer file. As of NetBeans 6.9, there are a number of annotations which can be used to generate the this XML data at compile-time.

Using declarative mechanisms, your objects will be instantiated when they are needed to do actual work. Until something really needs to call them, they don’t need to be created and their classes are not loaded.

If you really need to run some code on startup, create a subclass of ModuleInstall

Applies to: NetBeans 6.7 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 http://wiki.netbeans.org/DevFaqModulesDeclarativeVsProgrammatic , that was last modified by NetBeans user Tboudreau on 2010-02-18T19:38:16Z.

NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.