Geertjan is a DZone Zone Leader and has posted 457 posts at DZone. You can read more from them at their website. View Full User Profile

How to Create a Web Service Client with Groovy and NetBeans Platform 6.8

12.14.2009
| 47387 views |
  • submit to reddit

Setting up the Application

Let's start by creating a new NetBeans Platform application.

  1. Choose File > New Project (Ctrl+Shift+N). Under Categories, select NetBeans Modules. Under Projects, select NetBeans Platform Application. Click Next.

  2. In the Name and Location panel, type "ShakespeareSearch" in the Project Name field. Click Finish.


The IDE creates the ShakespeareSearch project. The project is a container for all the other modules you will create.

NetBeans Platform container

Run the application and notice that you have quite a few features out of the box already. Open some of the windows, undock them, and get to know the basic components that the NetBeans Platform provides without you doing any work whatsoever:

Note: Everything you see in the screenshot above can be hidden, if superfluous to your business needs, or enabled, e.g., the "Save" menu item can be enabled as described in How to Create a Swing CRUD Application on NetBeans Platform 6.8.

Once you've familiarized yourself with the framework of your application (by looking through the menus and clicking the buttons shown in the screenshot above), continue with the next section, where you'll wrap the three Groovy JARs into a NetBeans module and add it to the application.

Wrapping the Groovy JARs in a NetBeans Module

In this section, you add your first module to your application. The new NetBeans module will wrap the Groovy JAR files you worked on in the first section, above.

  1. To simplify the next step, put the three JARs ("groovy-all.jar", "groovyws-standalone-xxx.jar", and "ShakesGroovy.jar") into one folder somewhere on your hard disk. Once they are in the same folder folder, you'll be able to select them more easily, via Ctrl-Click in the wizard in the next step, when wrapping them into a NetBeans module.

  2. Right-click the ShakespeareSearch "Modules" node in the Projects window and choose "Add New Library". Select the three JARs ("groovy-all.jar", "groovyws-standalone-xxx.jar", and "ShakesGroovy.jar") by clicking "Browse" and then "Ctrl-Click" to select all three JARs in the folder where you put them above.

    Then complete the wizard, specifying any values you like, such as by filling in the values below:

You now have your first custom module in your new application, wrapping the JARs containing the Groovy-related classes. Take a look in your new NetBeans module's "Libraries" node in the Projects window and you will see your three JARs:

Right-click the new NetBeans module, choose Properties, and in the "API Versioning" node you will see that all the packages of the three JARs in the module are available to the rest of the applications. I.e., these are application-wide packages. That's the default. However, the only package you need to expose is the last one, i.e., "shakesgroovy", because that's the package providing the Java code compiled from your Groovy class, i.e., for interacting with the web service:

Therefore, if you like, you can uncheck the checkmarks for all the other packages listed in the dialog above, because all you need to expose to the rest of the application is the "shakesgroovy" package.

Now that the Groovy JARs are available in your application, the next section will show you how you can create a new NetBeans module that will access the Groovy class to retrieve Shakespeare quotations from the web service. Then we'll spend some time making a nice UI, using the many advanced Swing components that the NetBeans Platform makes available for free out of the box.

Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Cej Hah replied on Mon, 2009/12/14 - 2:40pm

Geeez, it's almost 2010, can't we get away from Big Web Services already?!  REST is your friend.  SOAP is your enemy.

Ning Sun replied on Wed, 2009/12/16 - 3:49am

Really nice article.

I have a question about the code when binding mouse listener to bean tree view. That is step 8 in "Using NetBeans Platform Swing Components", line 15. How you got the reference of resultPane in MyBTV? Is there any trick?

Thank u for your great article.

 

 

Sven Alfred replied on Thu, 2009/12/31 - 3:38pm

Great walkthrough. SOAP or not... doesnt matter.

Combining the power of the platform with the simplicity of Groovy. I will use this as recipe for my own platform experiments.

cheers

Sven

Jeff Schwartz replied on Fri, 2010/01/29 - 9:16am

@Geertjan,

Very groovy to see these examples in Groovy. IMO Groovy is the gem of the Java virtual machine. I find myself using it a lot. I fall back to Java when I can find a legitimate reason to, such as when addressing critical performance issues. Otherwise, Groovy just makes more sense to me.

A lot of the developers I speak with believe Oracle's purchase of Sun doesn't bode well for Netbeans. Nothing that I have read leads me to believe that Oracle intends to throw their 'official' support behind it. Maybe now is time to set Netbeans free from any single corporate sponsor and before Oracle kills it with neglect.

 Be well.

 Jeff @ http://jeff-schwartz.blogspot.com/

Mateo Gomez replied on Tue, 2012/04/17 - 12:30am

 You just made my life easier

 

 mexican dessert recipes

Matt Coleman replied on Tue, 2012/04/17 - 12:43am

 

 this makes want to get to know netbeans...great job you guys

graphic design buffalo

Eugenios Ampelius replied on Mon, 2013/09/30 - 10:49am

 Groovy does a great job. What's the deal with REST, though? I haven't used it. Is it really better than SOAP? Thank you.

Cata Nic replied on Mon, 2013/09/02 - 4:10am

 The platform can be extended to something custom and dedicated do the client's needs ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.