Aditya Chandak
Aditya Chandak

Reputation: 25

Quietly disable modules at run time in netbeans

I am working on a Netbeans Platform Application which has a few modules added to it. When I run the application the modules are loaded by default. Is there a way in which I can keep the default state of the modules as Inactive and then the user can activate the required module from the Plugin tool available in the application. If yes please guide.

Upvotes: 2

Views: 1506

Answers (1)

ShaggyInjun
ShaggyInjun

Reputation: 2963

The documentation says there is support for disabled modules.

Enablement

The standard module system permits modules to be in several states, controlled by external configuration:

  • Unknown. Either the module is not present at all, or the JAR is present but its config file is missing or masked.
  • Disabled (regular). The module is present and known but not loaded.
  • Enabled (regular). The module is present and loaded.
  • Autoload. The module will be enabled if and only if some regular enabled module requires it as a dependency (perhaps indirectly).
  • Eager. The module will be enabled if and only if all of its dependencies can be satisfied without enabling any additional regular modules.

Regular modules are used when their functionality is somehow visible just by virtue of being enabled - typically because they make layer registrations. Since this functionality might or might not be wanted it is important for the user or deployer to retain control over the enablement status.

Autoload modules are used for libraries. If there is no "client" of the library, there is no purpose in loading its JAR at all. Only when some regular module requires it (directly, via tokens, etc.) will it be loaded.

Eager modules are often used for "bridges" between otherwise independent pieces of functionality, represented as regular modules. If both of those modules are enabled, the eager bridge will be as well, integrating them using some optional service. They may also be used as add-ons to regular modules distributed via other channels; or as platform-specific modules that will be enabled only according to operating system tokens.

Note that these enablement states are not intrinsic to the module, which is why they are not specified in the JAR; they are part of its deployment. Another module system might not make any use of such distinctions. In particular, modules deployed via JNLP or OSGi are simply enabled by virtue of being included in the deployment set, or at the mercy of the container.

Module Enablement

Approach 1

I would try configuring the plugin like this if you are using maven.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>nbm-maven-plugin</artifactId>
    <version>3.13</version>
    <extensions>true</extensions>
    <configuration>
        <moduleType>disabled</disabled>
    </configuration>
</plugin>

Approach 2

If that doesn't work, create a file called module.xml inside the src/main/nbm directory and add the following lines in there.

<?xml version="1.0" encoding="UTF-8"?>
<nbm>    
    <moduleType>disabled</moduleType>
</nbm>

Then register the module xml with manifest file like this.

OpenIDE-Module-Layer: ro/emilianbold/nbmagazine/tutorial/layer.xml

NOTE: use of module.xml was deprecated as of mvn-nbm-plugin 3.7 if I am not wrong. So if you are using the latest version this might not work. For latest versions, the first approach is recommended.

Upvotes: 1

Related Questions