Installing things declaratively as opposed to programmatically

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

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 @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