Optional Module Dependency

cobusve <[email protected]> Fri, 3 Nov 2017 13:30:37 -0700 (MST)
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <[email protected]>
I have ModuleA which Optionally needs ModuleB. What I mean is that I want to
use a class in Module B only if it exists, if not I am OK with that, we just
do not use it.

Essentially I want to do in Module A:

try { ModBClass  foo = new  ModBClass();}
catch (NoClassDefFoundError) ...

And then going forward not use the functionality when not present.

What I have tried :

I can make this happen using reflection, but that is too ugly to accept.
There must be a better way !

I have compiled ModuleA, which results in info.xml containing
"OpenIDE-Module-Module-Dependencies="ModuleB". If this is present the module
will not install. If I remove it the module installs but does not load. If I
add OpenIDE-Module-Recommends="ModuleB" it still installs and does not load. 

I get an error dialog stating 
"Warning - could not install some modules: ModuleA - The module named
ModuleB was needed and not found."

All I find in the logs is "Warning - could not install some modules:
	ModuleA - The module named ModuleB was needed and not found."

Note that when I run/debug the ModuleA project from the IDE it opens a
NetBeans instance and runs just fine and works as expected when ModuleB is
present and also when it is not present.

It seems like the process of loading of ModuleA in Netbeans IDE when running
normally does some additional checks which prevents the module from loading. 

So where is the magic sauce ? If I understood what Netbeans is doing when
loading the module I could try and figure it out. My modules do not contain
any class member properties or statics so just loading the module should not
trigger any errors. It seems almost like the Netbeans module loader is
re-checking my imports, so how do I tell it that I know what I am doing do
not worry ?

ps. This is similar to the case described here 
http://netbeans-org.1045718.n5.nabble.com/Optional-module-dependency-td3027893.html



--
Sent from: http://netbeans-org.1045718.n5.nabble.com/Netbeans-RCP-Platform-Users-Open-API-f3018772.html