Showing posts with label Netbeans. Show all posts
Showing posts with label Netbeans. Show all posts

Monday, March 15, 2010

Return of some useful plugins in Netbeans6.9

The introduction of Netbeans6.8 was a mixed blessing. Its support for JSF2.0 and ease of development at various-fronts is indeed praiseworthy but the downside was that we lost many useful plugins including visual web tool for JSF development, UML editor, XML schema editor etc. The howls of anguish were widespread. Sun justified it on the basis of instability of some of the tools and the strategic need to marshal resources on winning fronts. Well, Netbeans6.9 early release have some of these back. It indeed is a good news for champions of these tools but it leaves the question answered on the future direction of these tools in the hands of Oracle. The departure of Sun's CEO Jonathan Schwartz, the chief open source officer Simon Phipps and Java technology evangelist Sang Shin (whose javapassion.com was a useful tool for learning various Java technologies) is indicative of the winds of change. Are these back because of the transitional uncertainties? Whatever the reason, enjoy while they are available.

Many know how to add a new plugin in Netbeans using Tools/Plugins/Available Plugins but fewer are certain of Tools/Plugins/Downloaded/Add Plugins which allows the .nbm (the Netbeans distribution files or Netbeans Modules files) to be incorporated in our 'User Installed Plugins) section. The latter option is the one you need to use if you are downloading a zip file from the Sun's site with the appropriate plugin and want to include it in your environment.

I recall an interview of Leo Apotheker (SAPS's ex-CEO) at Charlie Rose last year where he surmised that SAP may even get in the business of producing hardware devices. The rationale was that the software could easily integrate into remotely monitoring utilities meters and other devices and as BI Accelerator shows that the marriage is inevitable in many cases. Whilst there is feverish speculation on the direction of Java, MySql, OpenOffice etc under the aegis of Oracle, it may well be that it is the hardware/software marriage which underpins the acquisition. But it is hard to remain sanguine about these technologies future under a profit-driven acquisitor like Oracle. The Netbeans tools mentioned above may have gained temporary life while Oracle rationalises their product portfolio. So let us temporarily enjoy their availability whilst there are transitional uncertainties.

Creating and consuming a web service using Netbeans

Here are the steps for creating a simple service which allows two numbers to be multiplied:
  • create a new web application project called MultiplyApp (File/New project/Java Web/Web Application)
  • Click on the MultiplyApp node in the project and add a new web service called MultiplyWS (new/Web Service and type MultiplyWS as the Web Service Name and raj as the Package)
  • Expand the new created Web Services folder and look at the source of MultiplyWS. The default skeleton code should be showing error on MultiplyWS class as it has no operation as yet.
  • Right click within the class definition and define the multiply operation with long return type and two int type parameters i and j (insert Code/Add Web Service Operation)

  • Change the MultiplyWS. java code from return 0; to return i * j;
  • Right click on the MultiplyApp node and select Deploy to deploy the web service.
  • Right click on MultiplyWS in Web Service folder and select Test Web Service to see the service behaviour.
  • Right click on MultiplyApp and select Properties and then choose Run category and change the relative path to /MultiplyWSService?Tester
At this stage our service is ready but we need service consumers which can be any Java application, a servlet or a JSP. We cover the steps for the Java application in some detail but the process for creating a JSP or servlet consumer follows the same pattern.

  • Create a new Java application project called MultiplyClient (File/New Project/Java/Java Application). Leave the Create Main Class box checked while creating.
  • Right click on the project name MultiplyClient and create new web service client (New/Web Service Client). Select the MultiplyWS service in Project by using Browse.
  • Right click within main method of our Main.java class and select Insert Code/Call Web Service Operation and choose multiply from the available web service references.
  • Set the values of i and j and add in a code to print exception if you want.
  • Run the project and verify that the console printed the correct multiplication of i and j variables which we set in the previous step.
The process for creating the JSP or servlet-based client is the same, barring the fact that when we create a new project we choose File/New Project/Java Web/Web Application. We go through all the steps as above but we add the logic in a new servlet or a JSP and set the relative path in the project/properties/run accordingly to make these the entry points. Obviously the syntactic changes would be there to reflect that we are dealing with a servlet or a JSP when Insert Code/Call Web Service Operation happens. The only point worth mentioning is that the multiply operation can be dragged from the Web Service References to the appropriate point in the code to auto-generate the appropriate logic for the service call at that point. Thus for JSP we get this:



Experiment and enjoy!