Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can code in one module be notified when other modules are loaded or unloaded?

0
Posted

How can code in one module be notified when other modules are loaded or unloaded?

0

Let’s begin by stating that you probably do not need to know when other modules are loaded or unloaded. The module system takes care of dependency management for you, so your module should never be loaded unless all of its stated dependencies are loaded too. The normal means of communicating between modules about available services (which you could consider indirect dependencies) is using the Lookup API. If what you really wanted was to know when a service became available, you do not need to listen to module load or unload events as such; which module hosts the service is not of direct interest. Instead: • Define a service some.Interface in some module. • Implement that interface using some.Implementation in some other module. • Register that implementation: —%<--- src/META-INF/services/some.Interface some.Implementation ---%<--- (In NetBeans 7.0+, you can simply use the @ServiceProvider annotation.) • In some module consuming the service, use import some.Interface; // ... private s

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123