Oracle Blog

Blogging for Sun at UFRJ!

Quinta-feira Ago 07, 2008

A friend made a question on the WebServices and JSP on NetBeans 6.1 post about deploying Web Services on other servers, like Tomcat. It could be, actually, a problem, because many will say that you won't be able to deploy WS on Tomcat. That is not true. If you are using a version of JDK greater than 1.6.0_04, nothing needs to be done, you will just have to use TomCat on your project. If you are using older versions, you may check this link http://wiki.netbeans.org/FaqEndorsedDirTomcat.

I will do some demonstration here using Tomcat 6.0.16 that cames bundled with NetBeans 6.1 using JDK version 1.6.0_07 and JBOSS version 4.2.2 that I downloaded some time ago from www.jboss.org.

First, let's do our simple WS - that will receive a name as a parameter and return Hello name. Quite simple
I will not get into details here because the other post has already covered the Web Service easy creation on NetBeans.
Just ask for a New Project on NetBeans (File->New Project or Ctrl+Shift+N). Select a Web Application, using the Web Category and press Next. Choose a name for your application (for example: HelloTom) and press Next again.
On this screen, you choose the server you will use for the project, select Tomcat.

Press Finish.
After project creation, right click the project name (HelloTom) and select "New->Web Service" from the drop down menu. On the wizard screen, define the Class and package name for your WS (like Hello and hello.ws). NetBeans will open your WebService for visual development.

Click on the "Add Operation..." Button. On the wizard screen, select the name of the operation (i.e. helloOperation). Do not use just 'Hello' as the name of the operation because it will be interpreted as the WS class constructor and you may get confused. Leave the Return Type as String but add a String parameter called "name". Click OK and see that the visual designer added your operation to the WS Operations list on the screen. Right Click the helloOperation and select "Go To Source".

Done. Now, right click your project name (HelloTom) and choose Run. If Tomcat is up and running, it will show the Hello World! message for you that is on its default JSP page.
The "Test Web Service" functionality we have used on the other post will not be avaiable on Tomcat like on Glassfish, but you can easily try your WS creating another project that access the Web Service on the server. If you have problems creating a project to access the WS, check the WebServices and JSP on NetBeans 6.1 post.

Now let's add another server to NetBeans and make use of it.

Click on the Services tab, on the left side of IDE. Righ Click the Server node and click on "Add Server..." just like the next picture:

The Wizard starts and you need to choose the Server type. Here, on my example, I chose JBoss Application Server (but there are many others):

Press Next. On the next screen, select the server location (ie, where is it installed) and press Next again.
On this screen, you will need to select a server configuration, I've just left the default:

Press Finish. The Server will be added to your Server list on the IDE. You may right click on its icon and Start the server just like this (Iniciar=Start, in Portuguese):

Wait until JBOSS starts and let's test it.

Go Back to your projects clicking on the Projects Tab. Right Click the Hello Project and select Properties from the drop down menu. On the Properties screen, select the Run category (that may be the last one) on the left panel just like the next picture (the picture has somethings in Portuguese where Run=Executar). After selecting the Run category, you will see (on the right side) the option to select the server where you want to deploy your project, we will have Tomcat selected, change it to JBoss Application Server.

Press OK and wait while NetBeans save your project's Settings. Now your can Run the Hello project again and it will be deployed directly on JBoss. The "Test Web Service" functionality is not avaiable on JBoss too, you need to create another simple project that access the Service on the server. It'easy and described on the WebServices and JSP on NetBeans 6.1 post.