// 
//     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.
//

= DevFaqModulesDeclarativeVsProgrammatic
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqModulesDeclarativeVsProgrammatic
:description: Apache NetBeans wiki DevFaqModulesDeclarativeVsProgrammatic
:toc: left
:toc-title:
:syntax: true

=== 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 link:http://platform.netbeans.org/[NetBeans Platform-based application] involve a text entry of some sort,
such as link:DevFaqModulesLayerFile.asciidoc[putting something in an XML file]), or a plain-text file naming some classes in your JAR file's `META-INF/services` directory &mdash; _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 [link:http://bits.netbeans.org/dev/javadoc/org-openide-util-lookup/org/openide/util/lookup/ServiceProvider.html[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 link:DevFaqModulesLayerFile.asciidoc[XML layer file].  As of NetBeans 6.9, there are link:http://wiki.apidesign.org/wiki/CompileTimeCache[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 `link:http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/ModuleInstall.html[ModuleInstall]`

link:DevFaqWhenToUseWhatRegistrationMethod.asciidoc[More about registration mechanisms]
<hr/>

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 link:http://wiki.netbeans.org/DevFaqModulesDeclarativeVsProgrammatic[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.
