Skip to main content

Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse - Part 3

Posted by arungupta on February 5, 2007 at 9:17 AM PST

In this third and last part of a
blog series (part
1
and part
2
), I plan to explore the steps to develop/deploy/invoke a Web service
on GlassFish using Eclipse IDE.

Eclipse does not offer GlassFish as a a bundled container. Instead you need
to install GlassFish
plugin for Eclipse
explicitly. The plugin requires WTP 1.0
installed in Eclipse so I
did that following the instructions. After installing WTP, I configured GlassFish
v2 M4
following rest of the plugin
install instructions
.

Here are the steps I followed to successfully build and deploy a Web service:

  1. Create a new "Dynamic Web Project" with name "hello"
    as shown
    here
    . Note the target runtime is "GlassFish V2 Java EE 5".
    Click Next.
  2. Uncheck "Sun DD Files" in "Project Facets" window as shown
    here
    . Click "Next" and "Finish" buttons.
  3. In "Projects" pane, expand the "WebContent",
    "WEB-INF", and open "web.xml" as shown
    here
    .
  4. GlassFish has a Deployment
    Descriptor Web service deployment
    but Eclipse seems to require
    "web.xml" for a WAR. So replace the contents of "web.xml"
    with a simplistic fragment shown below:



    <?xml version="1.0" encoding="UTF-8"?>

        <web-app xmlns="http://java.sun.com/xml/ns/javaee"

              
        xmlns:j2ee="http://java.sun.com/xml/ns/javaee"

               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        version="2.5"

               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

                              
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

        </web-app>
  5. In "Projects" pane, right click on "Java Resources"
    and create a new package as shown
    here
    .
  6. Right-click on the newly created package and add a new class
    "Hello" as shown
    here
    .
  7. Add the @javax.jws.WebService annotation and a method as shown below:

    @javax.jws.WebService

        public class Hello {

          public String sayHello(String name) {

            return "Hello " + name;

          }

        }
  8. Select "Project" menu, "Build All" (default shortcut
    Ctrl+B).
  9. In "Projects" pane, right-click on the project, select "Run
    As", "Run on Server". Take the defaults (GlassFish V2 Java EE
    5) as shown
    here
    . Click "Next" and "Finish" buttons.
  10. The endpoint gets deployed as shown
    here
    . This can be verified by clicking on the "Servers" tab,
    and expanding GlassFish node as shown
    here
    . The endpoint is hosted at http://localhost:8080/hello/HelloService?wsdl.

So far we have been able to deploy JAX-WS based Web service on GlassFish.
Eclipse allows generating
a Web service client using Axis run-time
environment only. So as with
IntelliJ, if you want to invoke a Web service using JAX-WS, the recommended way
is to use NetBeans 5.5.1 to invoke
the Web service
.

Enjoy Web services deployed on GlassFish
in Eclipse! And remember, GlassFish v2 uses Web
Services Interoperability Technology
(WSIT) that gives you interoperable Web
services with Microsoft .NET 3.0 framework.

So if you want first-class Web services support in an industry-grade,
cross-platform IDE and deploy it on an open source, production-quality, Java
EE5-compatible Application Server, NetBeans IDE
is the only choice.

Technorati: NetBeans IntelliJ
Eclipse GlassFish
Web service WSIT

Related Topics >>