1
votes

Can I create a module for NetBeans that runs in the background as soon as the user opens the NetBeans IDE? For example, I am building a plugin that captures the source code of the active JTextComponent (active code editor) in NetBeans, but I would like this plugin to always run in the background without having to be activated by the user clicking a button or pressing some key combination.

Is this possible, and if so, what is the best way of doing it?

1

1 Answers

2
votes

Yeah, just create a "Install.java" inside the root package of your module and subclass it with ModuleInstall class, then start a process that runs continuously inside the restored() methods. The restored() method gets called on module installation and everytime netbeans starts. So your process will start as soon as the module is loaded in Netbeans.

ModuleInstall

Also checkout this section from DevFaqModulesGeneral.

Programmatic registration - ModuleInstall classes The module system allows you to provide a ModuleInstall class, which runs some code during startup or when the module is loaded, and can run cleanup code when it is uninstalled or disabled. This is the least desirable way to do things, because running code on startup means slowing down startup. Before you use such a class, be sure there is no declarative way to do what you're trying to do; see: DevFaqModulesDeclarativeVsProgrammatic

To have some code run on startup/installation/uninstallation/etc., add a line like the following to your module's manifest file:

OpenIDE-Module-Install: org/netbeans/modules/paintcatcher/PaintCatcherModule.class

This line should be part of the group of lines at the top of the manifest, with no blank lines before it. It is a pointer to a class file inside the module. The class file must extend the class org.openide.modules.ModuleInstall. There is a wizard in the development support to create and register such a class for you.