X

Geertjan's Blog

  • May 9, 2005

NetBeans Modules for Dummies (Part 4)

Geertjan Wielenga
Product Manager
I made some progress with the Ant scripts that I use to create my NBMs. In the first part of this "NetBeans Modules for Dummies" pseudo-series, I mentioned several workarounds for problems that are caused, as it turns out, when the wrong version of nbantext.jar is used. In the openide-dev mailing list, which I only discovered today, Jesse Glick says the following in response to someone else querying the use of nbantext.jar: "The version in the release41 branch assumes the existence of
the nb.system.dir property, which is defined in directories.properties in that branch. The trunk version does not use this property (and the properties file is gone)."
Somehow I haven't been able to find the version that I should be using. So, instead, I've had to use the structure that my version (downloaded from the Update Center) demands. This structure happens to be identical to that used by Elan Meng and so I am greatful for having found his blog (and, of course, greatful to him for having written it).
So, the solution to using the "faulty" version of nbantext.jar is as follows (assuming that your module is called ColorSwitcher):
  1. Define the following in project.properties:

    cluster.dir=ColorSwitcher
    modules.dir=${cluster.dir}/modules
    modulexml.dir=${cluster.dir}/config/Modules
    module.name=ColorSwitcher
    nb.system.dir=config
  2. Add the following two scripts to your build.xml file:

    <target name="create-xml-file-for-module" depends="compile,jar" description="Create XML File.">
    <!-- Create directory for JAR. -->
    <mkdir dir="netbeans/${modules.dir}"/>
    <!-- Create directory for JAR's XML file. -->
    <mkdir dir="netbeans/${modulexml.dir}"/>
    <!-- Copy the JAR (therefore, you must build the JAR first!). -->
    <copy file="${dist.jar}"
    todir="netbeans/${modules.dir}"/>
    <!-- Create the XML for the JAR (therefore, must have an appropriate manifest.mf first!). -->
    <taskdef name="createmodulexml"
    classname="org.netbeans.nbbuild.CreateModuleXML"
    classpath="${javac.classpath}" />
    <createmodulexml xmldir="netbeans/${modulexml.dir}">
    <enabled dir="netbeans/${cluster.dir}">
    <include name="modules/${module.name}.jar"/>
    </enabled>
    </createmodulexml>
    </target>

    <target name="create-nbm" depends="create-xml-file-for-module" description="Create NBM File.">
    <taskdef name="genlist" classpath="${javac.classpath}"
    classname="org.netbeans.nbbuild.MakeListOfNBM"/>
    <genlist outputfiledir="netbeans/${cluster.dir}" module="modules/${module.name}.jar">
    <fileset dir="netbeans/${cluster.dir}">

    <include name="modules/${module.name}.jar"/>

    <include name="config/Modules/${module.name}.xml"/>
    </fileset>
    </genlist>
    <taskdef name="makenbm" classpath="${javac.classpath}" classname="org.netbeans.nbbuild.MakeNBM"/>
    <makenbm file="${module.name}.nbm"
    needsrestart="false"
    productdir="netbeans/${cluster.dir}"
    module="modules/${module.name}.jar"
    homepage="http://www.netbeans.org"
    distribution="http://www.netbeans.org"/>
    </target>

The above targets assume that you've added the related JARs to the javac.classpath property. Do this by right-clicking the project's Libraries node and adding the nbantext.jar, openide.jar, and openide-loaders.jar. This is the result when I run the two scripts:

Finally, I know that there's something called "cluster harness" available for building NBMs, but I'd rather do it myself with my own Ant script. Bunches of extra files, unless necessary, make things even more complex than they already are.

Join the discussion

Comments ( 4 )
  • Abhisek Thursday, September 27, 2007

    I want to add button action in the toolbar under the menue with some icon.how should i proceed.waiting for your reply...


  • Geertjan Friday, September 28, 2007
  • Mary Thursday, December 20, 2007

    I have created multiple modules and place them in a module suite. Everything is fine until I run the project. It seems that my modules cannot see classes from other modules that are in the same suite. I have spent 3 days on this, trying different configurations and still nothing workd. I get a "ClassNotFoundException" but when i looked at the modules\\ext\\jar files - the class is there.

    Could you help me?


  • Geertjan Thursday, December 20, 2007

    Hi Mary, why not take a tutorial, you'll learn a lot:

    http://platform.netbeans.org/tutorials

    Also, join the mailing list:

    dev@openide.netbeans.org


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.