Just another weblog

3, 2009 Running Groovy on the NetBeans Platform

Posted by damuchinni on February 14, 2009

Here’s a Groovy POJO:


public class DemoPojo {

    def foo


And here’s my ModuleInstall class (which is a NetBeans module’s lifecycle manager), which uses its restored() method to instantiate the POJO, set the variable, and then print out the variable. Oh, by the way, the class below is, just like the above, a Groovy class. The thing to notice is that I defined no getter/setter in the POJO above, because Groovy simply assumes I have them, and that there are no semi-colons at the end of the statements at all (thanks again Groovy).


import org.openide.modules.ModuleInstall as MI

public class Installer extends MI {

    public void restored() {

        for(int i = 0; i < 10; i++) {
            DemoPojo dp = new DemoPojo()
            println("Number: " + dp.getFoo())



Also, the “println” statement comes from Groovy, without my needing to import the class. Look also at the abbreviation for my imported class, which I can then refer to in that way in my class signature (and anywhere else). In fact, I could use any Groovy constructs at all now.

So the above two are in a module. The ModuleInstall class is registered in the Manifest, just like any other ModuleInstall class, because after compilation the Groovy class becomes a Java class. At that point, there’s no difference anymore.

To make all of the above possible, add the following to your module’s build.xml file:

<taskdef name="groovyc"

<target name="netbeans-extra">
    <groovyc srcdir="${src.dir}" destdir="${build.classes.dir}">
        <classpath refid="cp"/>
    <jarwithmoduleattributes jarfile="${cluster}/${module.jar}"
           compress="${build.package.compress}" index="${build.package.index}"
           manifest="${}" stamp="${cluster}/.lastModified">
        <fileset dir="${build.classes.dir}"/>

So, after the Groovy compiler does its thing, the module’s JAR is recreated, using the output from the Groovy compiler. Note that, as indicated above, you need a folder in your module named “ext”, containing “groovy-all.jar”. You also need to put your module in a suite and set a dependency on a library wrapper module that contains “groovy-all.jar”.

Here’s the Projects view on my module, isn’t it cool to see only Groovy classes there?

Then you’ve got everything you need to run Groovy on the NetBeans Platform. Now excuse me while I go and create some file templates for Groovy versions of TopComponents, Actions, and so on…


Posted in IDEs | Tagged: | 2 Comments »

Simple & Useful : Remote debugging with Ant

Posted by damuchinni on March 25, 2009

A Ant java call like :

becomes :

and is ready to be launch and ‘remote debugged’ from a tool like Eclipse IDE.

Posted in Debugging in IDEs | Tagged: , | Leave a Comment »

NetBeans Platform Enables Intelligent Homes!

Posted by damuchinni on March 24, 2009

Marek Kliś works as a software developer for MCD Electronics, a company in Żywiec, Poland, which produces electronic equipment. It is his responsibility to develop software for the configuration of this equipment and for the visualization of the related functionality, more info about which can be found here. He also develops software for the company’s management system.

In addition, Marek is a fan of Java and its related technologies. He’s an active member of the Polish JUG and the Silesia JUG, where a recent NetBeans Platform Certified Training was held.
You’ve been using the NetBeans Platform at work. How did that happen?

Well, I needed to make software to configure the building management system worked out by my company. In the beginning, I started with Swing without any framework. However, it took too much time to create the user interface and the result was not satisfactory because the application was not friendly to the end user.

So then I started to look around for a framework that could help me. I came up with two possibilities: Eclipse RCP and NetBeans Platform. After a few tests I chose the NetBeans Platform, which seemed to be the right solution for my Swing application.
What exactly is the application you’re developing?

The application is needed for configuring the system that controls the lighting, heating, and opening/closing of gates in houses. In the building sector, a system of this kind is known as an “intelligent home”. Our goal is to create a multipurpose system available for home management.

Therefore, the application has to be easy to use and intuitive to install. It also needs to be very simple to maintain. Even the most complicated system functions must be simple to configure.
What are the main features and highlights of the application?


The application has its own project type. A “project” consists of a database and some specific XML files that can be visualized and modified graphically by user, thanks to the Visual Library’s widgets. The database contains the complete system’s configuration.

The user can create a separate project for each installation.

Every installation is different. It can consist of up to 640 specific logical modules. Each module has to be configured and the user must configure the connections between modules. The application helps to do this by means of several wizards.

The application helps to restore system configurations if/when the hardware crashes.

How is the NetBeans Platform helping?

Thanks to the NetBeans Platform, I was able to concentrate on the application logic, since the NetBeans Platform made the various GUI mechanisms available to me.

For example, I found the Visual Library very helpful for my purposes. The Visual Library provides widgets that helped me to illustrate the connections between the system elements in a very simple way. For this reason, the system configuration has now become very easy and fast:

Another useful part of the NetBeans Platform is its Wizard API. The Wizard API helped me create a set of wizards that make some operations much easier for the end user:

What are your favorite features of the NetBeans Platform?

The Visual Library API is one of the coolest libraries on the NetBeans Platform. It enables you to illustrate graphically the different data sets and data schemes in a very simple way.

Another favorite feature for me is the fact that NetBeans Platform is built on Swing!

The third and most important NetBeans Platform feature is… that it is an open source project! I can look at the NetBeans Platform source code and see how the NetBeans engineers use the various platform libraries. That’s very helpful.
What could be better?

I encountered difficulties regarding refactoring. Not every change of class names causes a related change in the XML configuration files, i.e., the layer XML file.

In my opinion, it would be great to have a tool for including automatically all the necessary libraries needed in the Project Properties dialog, for the NetBeans Module Suite project type. For example, if I include a module that depends on 10 others, I currently need to find and explicitly include them manually one by one! NetBeans IDE informs only about the first dependency, and after resolving it, NetBeans IDE informs about the next one, and so on, which is a bit cumbersome.
Can you give a few tips and tricks for getting started with the NetBeans Platform?


Start at the NetBeans Platform homepage. There are many tutorials and a lot of documentation that can help you to get acquainted with the NetBeans Platform.

Next, take a look at screencast series “Top 10 NetBeans APIs”.

I recommend to download the NetBeans IDE source, where you can find a ready solution for most problems.

Subscribe to the mail lists and, if you want to use the Visual Library. Don’t be afraid to ask questions if you don’t find answers in the archive!

Look at PlanetNetBeans is an aggregator of NetBeans-related musings from all over the blogosphere.

When will the application go into production? What are the main features you will add in the future?

The application, as a Beta, has just become available. The application needs to be extended with a reporting system. In the future, we plan to add a module that will show system state in real time.
Any other thoughts to share?

I think that the NetBeans Platform is a perfect solution for building modular desktop applications.

Let’s concentrate on application logic and don’t try to solve problems that have already been solved by NetBeans engineers, such as modularity and a window system.

Finally, I’d like to thank the Polish Team for translating the NetBeans Platform into Polish. It made my work a lot easier because one of the requirements was that it had to be in Polish!

Posted in IDEs | Tagged: | 1 Comment »

Type conversion in Java

Posted by damuchinni on March 15, 2009

The type conversion in java of two types.
a)Automatic type conversion

Automatic type conversion: When one type of data is assigned to another type of variable an automatic type conversion will take place.
Conditions 1)The two types are compatible 2)The destination type is larger than the source type.
int x=10;
byte y=2;
x=y; byte to int automatic conversion.

Casting: It is used to perform conversion between incompatible types.
Syntax: (Target_type)value
Target type specifies the desired type of convert the specified value to.
Int i=257;
Byte b;
B=(byte)i; //now b value is 1.

Posted in Java | Tagged: | Leave a Comment »

Contracts? Test-driven? Insight!

Posted by damuchinni on March 14, 2009

The other day I pair-programmed with a new guy at work. He showed my a class and its tests he and another guy had written a few week earlier. I don’t recall exactly what the class did, but it was quite simple, hence the tests was short and simple. Overall well written tests if you ask me.

As we looked at the tests we had the following conversation, which afterwards gave me an new insight to an idea I’ve had a long while: tests are contracts.
He: Most of these tests are for testing that the class logs correctly…
Me: Yes, is that a problem?
He: Well, I know TDD says that you need to write a failing test before you’re allowed to write any production code. But isn’t testing logging a bit over-kill?
Me: I understand what you mean. What kind of logging is this? Why does the class need to log?
He: We needed it to understand the code. For debugging.
Me: Is the logging needed now? Is there some script that parses these logs, for example?
He: No, it’s not needed any more.
Me: In that case I’d say that these tests isn’t needed.

I could go even further and say that those tests shouldn’t be written at all and should be removed. I actually think that tests like these are more confusing then anything else. I’m not saying those two guys who wrote these tests did anything wrong; they were doing TDD and was doing TDD right. What I’m saying is that, in my opinion, TDD isn’t ideal.

Yeah, I hear you’re cries: What?! Heresy! Calm down. I’ll try to explain.

My opinion is that a class’ tests should define what the class has to fulfill to be considered correct. To be precise, with ‘correct’ I mean ‘what makes all things that depend on the class behave correctly’. (I realize that this is an recursive definition of ‘correct’, but you’re a human being so you can handle it. :))

Recall that my pair-programming partner said that the logging wasn’t needed any more. This means that we could remove the part of the code that logs and the class would still be correct according to the definition above. However, the class would not pass its tests because of the tests that tests the logging. This means that the class is over-specified. This is bad. The solution? Ditch the logging tests!

And so my fellow pair-programmer did.

I often say that test-methods should be named shouldFoo since it makes you focus on the behavior that is tested instead of the part that is tested (the tested method for example). I’m thinking of extending this tip to nameing test-methods as shouldFooBecauseBar. If this convention was followed, the the test-methods that tests the logging whould be named shouldLogBecauseWeNeedItforDebugging. That name sound a bit silly, doesn’t it? That because it is silly to test it!

As I said, a class’ tests defines what the class has to fulfill to be correct. In other words, the tests is the contract that the class must fulfill. Having tests that define contracts is much better, I think, than having tests for every little piece of functionality a class have (i.e., TDD). One reason is that it makes it easier to understand how you can change the class without breaking anything.

Now don’t get me wrong, TDD is great, really great. But is it perfect? Of course not, that would be very naive to think (not to mention boring: Nothing more to do here, we’ve find the ideal solution! Now, let’s drink tea all day!).

Is contracts ideal? Probably not. It contracts better? Yes, I think so.

Posted in Test Driven Development | Tagged: , | Leave a Comment »


Posted by damuchinni on March 14, 2009

1. dependency jar : “” verison “” can’t be download automatically. need to be manually download form here and copy it to the \ivy-cache\repository\org.xmlpull\\

2. set ANT_OPTS before you start if you got a java.lang.OutOfMemoryError: PermGen space exception.

set ANT_OPTS=-Xms256m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m

Posted in Springs | Tagged: | Leave a Comment »

unrooted tests of junit 3.4 runner

Posted by damuchinni on March 14, 2009

When using Eclipse 3.3 or above, By the default, the JUnit 4 test runner will be used. In the olden days, with Eclipse 3.0 and JUnit 3.8, user could select a single test method in the Outline view and run just that method. However, when try to do that in Eclipse 3.3 or above. It’s test runner runs all the tests in the class. The results are shown in a tree, and the tests I didn’t ask to be run are all under a node called “Unrooted Tests [Runner: JUnit 4]”.

The problem is because,your class extends TestCase (in Junit 3.8 favior,not use the 4.0 annotation), but eclispe will Using the JUnit 4 runner by the default which causes that unrooted test. if you want to use the old Junit 3.8 runner for your 3.8 testcase. you have change the run configurations manually.

the old Junit 3.8 runner will show up after that:

Posted in IDEs, Junit | Tagged: , , | 1 Comment »

Test Driven Development

Posted by damuchinni on March 14, 2009

What is TDD?

Test-Driven Development (TDD) is a software development technique consisting of short iterations where new test cases covering the desired improvement or new functionality are written first, then the production code necessary to pass the tests is implemented, and finally the software is refactored to accommodate changes.

Practitioners emphasize that test-driven development is a method of designing software, not merely a method of testing.

Test-Driven Development Cycle

Add a test

In test-driven development, each new feature begins with writing a test. This test must inevitably fail because it is written before the feature has been implemented. In order to write a test, the developer must understand the specification and the requirements of the feature clearly. This may be accomplished through use cases and user stories to cover the requirements and exception conditions. This could also imply an invariant, or modification of an existing test. This is a differentiating feature of test-driven development versus writing unit tests after the code is written: it makes the developer focus on the requirements before writing the code, a subtle but important difference.
Run all tests and see if the new one fails

This validates that the test harness is working correctly and that the new test does not mistakenly pass without requiring any new code.
Write some code

The next step is to write some code that will cause the test to pass. The new code written at this stage will not be perfect and may, for example, pass the test in an inelegant way. That is acceptable because later steps will improve and hone it.

It is important that the code written is only designed to pass the test; no further (and therefore untested) functionality should be predicted and ‘allowed for’ at any stage.
Run the automated tests and see them succeed

If all test cases now pass, the programmer can be confident that the code meets all the tested requirements. This is a good point from which to begin the final step of the cycle.
Refactor code

Now the code can be cleaned up as necessary. By re-running the test cases, the developer can be confident that refactoring is not damaging any existing functionality.


Starting with another new test, the cycle is then repeated to push forward the functionality. The size of the steps can be as small as the developer likes, or get larger if s/he feels more confident.
TDD Benefits


Improve software quality by providing 100% test coverage.

Improve code design by forcing developer to think outside of the code as a critics.

Increase developer productivity.

”A 2005 study found that programmers that wrote more tests tended to be more productive” (see the research at


Minimize/Remove debugging/troubleshooting time.

“Programmers using pure TDD on new (”greenfield”) projects report they only rarely feel the need to invoke a debugger” (see


Code Implementation time is shorter.

“While it is true that more code is required with TDD than without TDD because of the unit test code, total code implementation time is typically shorter.” (see


Makes Refactoring easy by removing bug fears.

TDD Disadvantage


The tests themselves become part of the maintenance overhead of a project.

Developer aptitude towards writing test case.

Management support is essential. (

Posted in Test Driven Development | Tagged: , | Leave a Comment »

WebKit Component for Java, Second Contestant

Posted by damuchinni on March 14, 2009

While there weren’t any news related to Sun’s JWebPane, there is a new contestant: WebKit for SWT by Genuitec. The website says:

WebKit for SWT (ver. 0.5) is an embeddable Java™ WebKit browser component developed by Genuitec. This component can be used in the development of a wide range of Java SWT applications that require integration of rich HTML5, CSS3, JavaScript and Flash content and functionality.

The solution seems a little bit more high-level than Sun’s approach: While Sun is integrating WebKit directly, Genuitec build on top of Google’s chromium. The biggest difference however at this time: They provide code, documentation and samples.

Posted in Java, swings | Tagged: , , | Leave a Comment »

Dynamic Java Programming With Rule Engine

Posted by damuchinni on March 14, 2009

Rules are statements that define business procedures and policies. Normally, every business application contains many embedded business rules that determine business process flow and execution. When we program these rules with static languages like Java, there is no problem at all.

However, the problem is that some business rules change over time very frequently. It is very expensive to fix these changing parts since it requires new versions and software development cycles; develop, deploy on a test server, test, package, deploy on a production server etc. Here “Dynamic Programming” comes to our rescue. Our program doesn’t have to necessarily be written with a dynamic language. We can use this advantage in Java with Rule Engine mechanism.

Rule Engines don’t serve only the dynamic programming. They evaluate rules and extract some inferences by using some algorithms like RETE. This inference mechanism is hardly possible with many “if-else” statements in normal program code. Rule Engines have generally 4 types of rules;

* Constraint Rule: We may need to define restriction or limits for some entities. “A customer sales order amount must be lower than 100 if the plant is over capacity ”

* Validation Rule: Some validation rules may change over time. “Production order can’t be accepted if current day is Sunday”

* Action Rule: Some actions may be triggered. “Send a notification e-mail if a purchase order is over $1000 to boss”.

* Computation Rule: Some formula may be executed. “Discount is 20% if customer is Mr. Anderson”

We can use Rule Engines on the market but even we can write our own Rule Engine to benefit the dynamic programming in Java. By using Java compilers, classloaders, it is not so much hard. My favorite rule definition format is Java source code instead of some natural languages or XML. This can also reduce the overall development cost of your custom rule engine. By writing Java rule definitions, we can also use the IDE debugger features without learning a new syntax. If we develop our own Rule Engine, we may skip the inference engine part since we only want dynamic programming feature for now. Best place for plugging rule execution is database access layer. Rules should work invisibly behind the database objects. In some cases, some rules might be invoked from static program codes.

The benefits that we have when using Rule Engine are:

* Dynamic programming with hotswapping feature that provides fix&run easiness.
* Minimal cost of business rule changes that occurs many times.
* Accumulation of business rules in one place that may result re-usability and code repetition prevention.
* Dynamic validations that may change over time.
* Constraints can be defines for default values, assertion checks etc.
* In any time rule may be turned off/on.

Some of the features of Rule Engine may remind us database constraints and triggers. Using database may hinder portability and require DBA involvement. I think Rule Engine is better for business rule definitions. These database features may be used for other purposes.

The critical question we should ask ourselves is which part of business rules should be taken into Rule Engine from the programs. The answer is “frequently changing” rules. Some changing parts can be defined within parameter tables (processing options) but we can’t define computation or many if-else statements in these tables. But we should prefer parameter table if it is enough for the problem.







Posted in Java, rule engine | Tagged: , | Leave a Comment »

Visual Event

Posted by damuchinni on March 13, 2009

This is a really neat tool by Allan Jardine, a UI developer! It makes it so easy and visual to see what even handlers are attached to the elements of a page. Great addition to my toolbox!

When working with events in Javascript, it is often easy to loose track of what events are subscribed where. This is particularly true if you are using a large number of events, which is typical in a modern interface employing progressive enhancement. Javascript libraries also add another degree of complexity to listeners from a technical point of view, while from a developers point of view they of course can make life much easier! But when things go wrong it can be difficult to trace down why this might be.
Read the whole article about Visual Event

Posted in java script | Tagged: , | Leave a Comment »