//How to reuse modules across different NetBeans applications

If you develop NetBeans modules you probably also wondered how to add a pre-packaged .nbm file as dependency to your module or how to use modules in multiple suites.

After some search I found that there is currently no official supported way for doing this. The reason is the bidirectional dependency between the suite and each module in the suite. This makes it hard to reuse modules across suites but it is still possible. In this entry I will describe different techniques/hacks to workaround this issue. (Note: technique, hack and workaround in the same sentence ;) )

In general, you can add a dependency to a module when the module you like to depend on is in:

a) your suite

b) the target NetBeans platform (default target platform is the installed IDE)

As mentioned above a) works only for one suite -> only b) is left

option 1. Assemble your own target platform:

point and click

  • Either make a copy of NetBeans, or if there's a lot of stuff you don't want, create an empty suite. Then build it and create a zip distribution and unpack that
  • Launch the result
  • In Tools | Plugins, install the module(s) you want globally (check the "Force install into shared directories" checkbox)
  • Shut it down
  • In your real IDE, use Tools | NetBeans Platforms to point at the copy of the platform that now has the module you want in it
  • Set your suite to build against that. It should pick up the module you installed and all classes in it's public packages

or put it in a build script

option 2. Install the module into your IDE:

point and click

  • enable "Force install into shared directories" in Tools | Plugins | Settings
  • install your module(s)
  • restart NetBeans
  • your module is now in the extra cluster and part of your IDE

or declarative

edit Info/index.xml inside your .nbm file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//NetBeans//DTD Autoupdate Module Info 2.5//EN" "http://www.netbeans.org/dtds/autoupdate-info-2_5.dtd">
<module codenamebase="org.yourorghere.module4" distribution="" downloadsize="0" global="true"
homepage="" license="AD9FBBC9" moduleauthor="Michael Bien" needsrestart="false" releasedate="2008/04/07" targetcluster="milkyway">
    <manifest AutoUpdate-Show-In-Client="true" OpenIDE-Module="org.yourorghere.module4" OpenIDE-Module-Implementation-Version="080407"
OpenIDE-Module-Java-Dependencies="Java &gt; 1.5" OpenIDE-Module-Name="module4" OpenIDE-Module-Requires="org.openide.modules.ModuleFormat1" OpenIDE-Module-Specification-Version="1.1"/>
    <license name="AD9FBBC9">[NO LICENSE SPECIFIED]
</license>
</module>


alternatively you can add the flags to module/nbproject/project.properties and rebuild/create NBM (if source available)

nbm.is.global=true
nbm.target.cluster=milkyway

Now when you install the module with Tools | Plugins, NetBeans will place the module directly into the installation folder in the new created "milkyway" cluster. With this trick you should be able to use the same library wrapper module in as many suites you want.

Thanks to all on the mailing lists for the help on that topic.

------

I am already looking forward to JSR 277 which will hopefully replace the current implementation of the NetBeans module system. (no there was nothing anounced but this would make defenetive sense)


Share/Save/Bookmark


Comments:

Hi,
My name is James Branam and I'm the NetBeans Community Docs Manager. Your blog entry would make a fantastic tutorial for our Community Docs wiki (http://wiki.netbeans.org/wiki/view/CommunityDocs). Would you be willing to contribute it? If you need any help or have any questions, please contact me at james.branam@sun.com. I look forward to hearing from you.

Posted by James Branam on April 12, 2008 at 05:27 PM CEST #

Thank you James,
I converted the entry into a wiki page: http://wiki.netbeans.org/HowToReuseModules

Posted by mbien on April 15, 2008 at 12:46 PM CEST #

Hi,

Do you have an idea how to make this work in Mac OSX? I am trying to shift to Netbeans 6.0.1. I tried your recommendations above but it still doesn't work. It works in windows though. But I tried a different hack that works. It's by creating a directory called extra in my platform then copy the modules downloaded in my user directory files. Its not pretty and I was thinking if there was another way. I have no problems with reusing modules in 5.5.

Thanks

Posted by Elmo on April 30, 2008 at 01:05 PM CEST #

Hi Elmo,

sorry I can't help you since I am not developing on Mac OS but it is strange that NetBeans is behaving differently on a Mac compared to other platforms. (well NB has to be java 5 compatible because of Mac OS and has some special build targets...)

i recommend asking the question on the nb mailing lists again
http://www.netbeans.org/community/index.html
there are many devs on OS X around.

Posted by mbien on April 30, 2008 at 03:04 PM CEST #

Hi Michael,

Thanks. I'm using java 5. I'll just continue experimenting a little. Great article.

Elmo

Posted by Elmo on May 01, 2008 at 03:04 AM CEST #

Thank you Elmo, hope you find a solution.

Posted by mbien on May 01, 2008 at 02:24 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed