NetBeans Modules for Dummies (Part 4)

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.

Comments:

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

Posted by Abhisek on September 27, 2007 at 02:58 PM PDT #

http://platform.netbeans.org/tutorials/60/nbm-google.html

Posted by Geertjan on September 27, 2007 at 06:00 PM PDT #

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?

Posted by Mary on December 20, 2007 at 08:40 AM PST #

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

Posted by Geertjan on December 20, 2007 at 01:18 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today