# taT | Hacking Modules..

Ever wondered, apart from extending the NetBeans IDE, or some application based on NetBeans Platform. What else can be done with the module?

### Brief Overview

Well, NetBeans IDE provides Module Development Support by providing 4 kinds of Project Templates;

1. Module
2. Module Suite
3. Library Wrapper Module
4. NetBeans Platform Application

I have some knowledge of the first two, so we will stick to them for the rest of this post. So, lets have a look at the simplistic module structure;

This is what you see when you expand the Project node in Files View. We will focus on platform.properties, project.xml. If you switch to the Project View, you would see the files with following names, visible under Important Files node.

#### NetBeans Platform Config

So, that’s basically the logical view of the file platform.properties. In the past, I have written some pretty useful tips and Tricks (contributed to NetBeans Community Docs) based on this file;

This is the logical view of the file project.xml. There’s one more useful tips and Tricks (contributed), that’s based on this file, which lets you add your module as friends to those modules, if you want your module to depend on the specification version of the same.

### Playing Tricks..

I will be making use of NetBeans 6.7 IDE. Although, these tricks should work well with NetBeans 6.x IDE. So, lets answer the question I asked in the beginning.. Generally, when you create Module project, you get an option to either create it as Standalone Module or Add to Module Suite.

#### Standalone Module

When you choose this option, you also get an option to select NetBeans Platform of your choice, along with Manage.. button. If you want to know more about that, refer this contribution.

Suppose, I choose NetBeans 6.5 Build (added with name as 65 in Platform Manager) as Platform and move ahead. I would be able to use 6.7 IDE to create module, targeted for NetBeans 6.5 IDE. The module’s platform.properties looks like this;

nbplatform.active=65

This would enable the running IDE to achieve the desired result, as mentioned above. Now, running the module will ofcourse launch NetBeans 6.5 IDE as Target Instance to see how your module works. This process might be slow, as you’re running full-fledged 6.5 IDE.

If your module doesn’t depend on clusters other than platform (which is by default). Then, you can tweak the file as follows;

enabled.clusters=\
platform
nbplatform.active=65

These clusters are bare-minimum essentials, that are enabled by default when you create the NetBeans Platform Application project using 6.5/6.7 IDE. The property enabled.clusters helps to enable only those clusters which are necessary to run this module.

Now, run your module and it will look like you’re running a NetBeans Platform Application having a single user-defined module. Here’s how module’s project.xml looks like;

<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>code.name.base.of.your.module</code-name-base>
<standalone/>
<module-dependencies>
<!-- Here are your module dependencies.. -->
</module-dependencies>
<public-packages/>
</data>
</configuration>
</project>

Note the bold-faced tag <standalone />, this tells the NetBeans IDE that your module is not part of any module suite. Its a standalone module, as you created.

If you decide to go with this option, you would then browse the filesystem to find the appropriate Module Suite project and then, move ahead.

In case of Module Suite projects, the enabled.clusters property automatically occurs/disappears, when you check/uncheck the modules and/or clusters from its Project Properties Wizard.

Note that the module, that becomes part of the suite, would use only those clusters which the suite has enabled. Along with that, suite-private.properties file is added under /nbproject/private. Also, take a look at the module’s project.xml;

<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>code.name.base.of.your.module</code-name-base>
<suite-component/>
<module-dependencies>
<!-- Here are your module dependencies.. -->
</module-dependencies>
<public-packages/>
</data>
</configuration>
</project>

Note the bold-faced tag <suite-component/>, this tells that NetBeans IDE that this module is part of a Module Suite project.

### Tips to Remember

You may convert your standalone module to become part of suite, or vice-versa. Just add/remove suite-private.properties (Per Suite Locator) file and tweak your Module’s project.xml and Module Suite’s project.properties.

Also, note that some changes have taken place in NetBeans 6.7 IDE, you may find out more over the web. One more thing, NetBeans 6.5 IDE added suite.properties file under /nbproject and had same tag as <suite-component/>. I think NetBeans 6.0 and 6.1 might do the same. Please try it yourself and let me know.

Stay tuned..

# taT | Hacking Project Properties

Yesterday, I recreated one of the Visual Library Sample  (basically a tutorial based on it at Dzone) using NetBeans 6.7 IDE on Windows XP Professional SP2. The sample was Java Application that had two JAR’s (present in the platform7 cluster of NetBeans 6.0 IDE) in its classpath.

I followed the tutorial and successfully executed the application. Fortunately, I have NetBeans IDE from 5.5 onwards, so there wasn’t any issue finding the JAR’s and adding them in the application’s classpath.

I didn’t knew whether it will work with cluster from higher release or not. Hence, I decided to give it a try by making use of clusters from 6.1, 6.5 and finally, 6.7.

### Playing Tricks..

Now, removing/adding JAR’s again and again can be boring/cumbersome if you have several releases stored under different hierarchies of your filesystem. So, I looked into the various files created under /nbproject to inspect how these JAR’s being referred.

When you right-click Libraries Node and click Add JAR/Folder..

You’re prompted with the dialog for browsing and then, selecting Reference/Absolute Path as per your choice.

I selected the platform7 cluster (see above figure) and selected the JAR’s shown in the following figure.

### /nbproject/project.properties

This file contains all the project related properties, that are accessed by build-impl.xml (created from project.xml automatically) for necessary Ant operations.

file.reference.org-netbeans-api-visual.jar=\
path\\to\\cluster\\modules\\org-netbeans-api-visual.jar
file.reference.org-openide-util.jar=\
path\\to\\cluster\\lib\\org-openide-util.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.org-openide-util.jar}:\${file.reference.org-netbeans-api-visual.jar}:\
${libs.swing-layout.classpath} The bold-faced text is added, once referenced JAR’s are added from Projects Window/Project Properties Wizard. Also, path\\to\\cluster refers to the directory where the platform cluster is stored. In case of the above application, here’s the path; E:\\OpenSource\\NetBeans_Archies\\NetBeans 6.0\\platform7 ### Playing with Clusters Now, as you can see the path\\to\\cluster is the same in this case. So, I introduce another property that will have the path as value. path.to.cluster.platform=\ E:\\OpenSource\\NetBeans_Archies\\NetBeans 6.0\\platform7 file.reference.org-netbeans-api-visual.jar=\${path.to.cluster.platform}\\modules\\org-netbeans-api-visual.jar
file.reference.org-openide-util.jar=\
\${path.to.cluster.platform}\\lib\\org-openide-util.jar

This way, the referenced JAR’s become dependent on this property. Now, one can also change the value of this property, i.e. if one is interested in using JAR’s from platform cluster of higher releases of the NetBeans IDE.

Then, NetBeans will automatically scan the project, to update dependencies. For instance, I opted for platform9 cluster from NetBeans 6.5 IDE.

path.to.cluster.platform=\
E:\\OpenSource\\NetBeans 6.5\\platform9

I just made changes at one place, that will be automatically reflected in other properties that depend on it directly/indirectly.

### Tips to Remember

However, you need to check your code, once you do these changes, as this might cause warnings on deprecated usage of certain API, when you build your application.

Also, if you do any error while editing your project.properties as for this scenario, or any other. You may end up seeing lots of error badges in your code and possibly, get an added menu item (Resolve Reference Problems..) in the project’s context menu.

Stay tuned..

# taT | Managing NetBeans Platforms

Recently, I asked a question on NetBeans Developers Mailing List about gaining better understanding of managing NetBeans Platform(s) within the NetBeans IDE.

You didn’t knew that, right? Well, I have also recently discovered that there’s a provision to manage “NetBeans Platforms” for almost every NetBeans Module Project (I guess). Although, I think I knew that this feature was there but never actually devoted time to see what exactly it does.

Yesterday, when I re-discovered this feature and decided to give it a try. I started exploring it and then, faced some issues. So, I raised the above question on the mailing list. I did receive a reply, however it has a different approach to the above problem. Not directly related to scenario’s I came across. As I await more clarification

Now, I got clarification I needed and indeed it should help me understand the way, NetBeans works in this scenario. I thought why not share this scenario with you people. Maybe, you might have faced same issues.

So, how exactly we make use of this feature? Just follow the steps and let me know, what did you observe?

## Here are the Tricks,

Firstly, run NetBeans IDE (bundled with either Java SE, Java or All technologies). I am using NetBeans 6.5 FCS for demonstration.

Now, goto Tools | NetBeans Platforms and generally, you would find same platform configured with your NetBeans IDE and that might be possible, only if you are not running any daily builds.

So, this figure might look familiar to you, if the above statements are correct. You can configure several platforms with your distribution. For instance, I have NetBeans 6.0, 6.1 installed, along with 6.5 which I am running. So, I will show you how to configure one of them,

Choose Platform Folder

This step will let you select the installation directory of other NetBeans distributions and let you configure the platform supplied by them.

Platform Name

You may edit the Platform Name as per your need, or keep defaults and click Finish.

This way you have added platform supplied by NetBeans 6.0 in NetBeans 6.5. Now, switch over to Harness tab and click the 2nd radio button to complete the configuration. This is done to let this platform use its harness to perform tasks related with module projects.

Similarly, doing for 6.1, the following figure shows that I have successfully configured the above NetBeans Platforms,

Now, you know how to add/remove NetBeans Platforms. Lets go further ahead and explore a bit more by taking a typical scenario..

## and some tips,

Assuming you made a plug in using NetBeans 6.0 (released in Dec ’07) to be compatible with the same. Soon after NetBeans 6.5 FCS (released Nov ’08) was available, you find that 6.5 work very fast compared to 6.1 and due its improved features, it will help you in reducing your development time.

So, you decide to rework on your module using latest features, however you still want that plug in to work only for NetBeans 6.0, here’s what you need to do.

Firstly, open your plug in project and right-click project node to select its properties. Now, goto Libraries and you would see there’s a drop-down list for selecting your choice of NetBeans Platform, against which you can build your module. This list of platform’s can be configured by clicking “Manage Platforms…” button and you will see the same image, shown earlier.

See how they are all related.. Isn’t it cool? By default,  the platform supplied by the NetBeans IDE you are running is selected.

Here’s one thing to keep in mind, that as you are reworking on an old project like this, you must make sure that you configure the NetBeans Platform for it with care, as not doing so will result in failing the build and adding irrelevant versions of module dependencies.

In our case, if you have configured NetBeans 6.0 as demonstrated above, you need to select that from drop-down list and then, select NetBeans 6.0 build to let your module perform tasks against platform supplied with NetBeans 6.0.

When, you run the module project, the above splash screen for NetBeans 6.0 pops up and now, you can see whether your module works or not. Hope this helps!

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Acknowledgements

Thanks to Tom Wheeler (NetBeans Dream Team Member and NetBeans Governance Board Member) for answering my question on the mailing list.

# taT | “Deploy on Build” Using JBoss

Recently, I had asked a question on NetBeans Forums on the “Deploy-on-Save” feature supported by NetBeans 6.5 IDE. Well, I know I can’t configure build script in such a way, so that it can deploy on save. However, I found a trick to deploy the war file everytime I build OR clean and build .

### Brief Overview

This trick will save your time and do lot more stuff with an existing shortcut, which you might have missed otherwise. Actually, I was working on a “Dynamic Web project” in Eclipse IDE where I was supposed to make use of its 2.0.0.Beta2 version using JBoss 4.0.5 GA (with Java EE Platform set to “J2EE 1.4” ). Eclipse was so slow and its editor support for JSP pages was doing no good. Probably, if I could have used a new release of Eclipse, then that might have helped. Still, I am not sure, its just an assumption.

Also, everytime I made changes I had to first right-click project node, then select “Run As > Run on Server” and if I made any changes during runtime, it was not deploying automatically. Although, “Project” menu showed project to be build automatically . So, I had to repeat the cycle again and again.

Due to the above stated issues/problems, I decided to import the complete project into NetBeans 6.5 IDE. Import was successful and I added the JBoss server into NetBeans IDE (“Tools > Servers” ). Now, project is successfully building and deploying. Its absolutely working fine.

Now, NetBeans 6.5 didn’t supported “Deploy on Save” feature for the web applications that were using JBoss Application Server (I am referring to the above release), as per my recent observation.

Then, when I made changes to the webpages in the earlier mentioned project, I still couldn’t deploy on save/build. So, I had to right-click the “Project Node” and click “Deploy”. This cycle is shorter one, still frustating if one makes changes frequently.

### Tricks..

Now, open your project’s build.xml file and here’s the trick you need to do;

  <target name="-post-dist">
<echo>Automatic-deploy</echo>
<!--antcall target="run-deploy" inheritrefs="-init-deploy-ant"/-->
<antcall target="run-display-browser" inheritrefs="-init-deploy-ant"/>
<echo>Done...</echo>
</target>

below;

  <import file="nbproject/build-impl.xml"/>

This was done to override the above mentioned target present in build-impl.xml file, but thats empty.

    <target name="-post-dist">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>

Now, whenever you do “Shift-F11” or “F11”, it will “clean & build” or “build” respectively and then, deploy the project to the server.

### Tips to Remember..

If you replace the following tag;

    <antcall target="run-display-browser" inheritrefs="-init-deploy-ant"/>

with

    <antcall target="run-deploy" inheritrefs="-init-deploy-ant"/>

The moment you use “Shift-F11” or “F11”, the project will deploy the “war” file, however it will not run the browser for you, as it was doing earlier. If you have better solution, or encounter some problems, do let me know. Hope this helps.

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

Enjoy NetBeaning!

# taT | I want to use GSF API’s?

Blogging after 2 weeks…I have been focusing on my college activities more, I should rather say that I was working on my final year project. So, I thought of sharing some key learnings with you!

#### Final Year Project

I am working on a project that’s based on NetBeans Platform. Initially, its intended to provide first-class support for NetBeans Wiki markup editing, syntax highlighting, auto completion, etc. This would help any user using NetBeans Wiki, to edit/create the pages and then, preview them locally (offline).

So, I asked Caoyuan Deng (NetBeans Dream Team Member), winner of NBIG Gold Award, experienced developer on integrating languages like Erlang, Scala into the IDE, on how to go about using GSF?

If you want to make use of Specification Version of GSF modules, he suggested to add my module as friend to the GSF modules. Making friends is an easy task (as per my experience). That’s possible in two ways-

Case #1- I commit my code to /main/contrib and request the GSF Module Owner to add my specific modules as friends. As I had already versioned my project with SVN at java.net! So, I went for the second way.

Case #2- I should clone the NetBeans sources, and then run my choice of NetBeans IDE. Then, open the necessary GSF modules (from the clone repos)- tweak them (so as to add my module as a friend).

#### Tips and Tricks

Actually, I made my module friend of all the three GSF modules- /gsf, /gsf.api and /gsfpath.api

So, you are required to open the /nbproject/project.xml file of one of the GSF modules and add a friend tag with text equivalent to the Code Name Base of your module.

<friend-packages>
<friend>code.name.base.of.my.module</friend>
</friend-packages>

So, open all these modules in your NetBeans IDE (6.0/6.1 onwards). Tweak those project.xml files by searching for a tag “<friend-packages>” there you would see many module’s code name base have been added as friends using tag “<friend>”, also specific packages can be added using tag “<package>”.

#### Build the sources…

Once you have followed the second approach, its time to build the sources. Firstly, open the project NetBeans Build System (/main-golden/nbbuild). To know more about how to build the sources, give it a read :) Here’s an excerpt from the entry-

I referred a document for information on Mercurial Access. So, I found out /main-golden would be fine for us. As its guaranteed that build would succeed..

Once you get the build successful, you must now run the IDE either from /main-golden/nbbuild/netbeans/bin/ OR extract the distributable zip you must have created by running the target “build”.

This blog has been contributed to NetBeans Community Docs Program and for latest updates on this content, refer to the contribution.

#### Finally,

Its done, now you can open your project modules in the newly created build of NetBeans IDE. As and when you make use of the Gsf API’s, build would definitely succeed.