[RSS]

Installing things declaratively as opposed to programatically

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 system involve a text entry, such as putting something in an XML file , not running Java code. Ideally a module should do nothing on startup. Let's say that again, forcefully: Ideally a module should do nothing on startup.

The main ways to do this are putting a file in your JAR's META-INF/services directory or creating an XML layer file that declares information about the things your module is installing. Then, when they are needed to do actual work, your objects will be instantiated.

If you really need to run some code on startup, use a ModuleInstall class.