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:
- Create a new "Dynamic Web Project" with name "hello" as shown here. Note the target runtime is "GlassFish V2 Java EE 5". Click Next.
- Uncheck "Sun DD Files" in "Project Facets" window as shown here. Click "Next" and "Finish" buttons.
- In "Projects" pane, expand the "WebContent", "WEB-INF", and open "web.xml" as shown here.
- 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> - In "Projects" pane, right click on "Java Resources" and create a new package as shown here.
- Right-click on the newly created package and add a new class "Hello" as shown here.
- 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;
}
} - Select "Project" menu, "Build All" (default shortcut Ctrl+B).
- 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.
- 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 services WSIT
Related posts:- Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse – Part 1
- Creating and Invoking a Web service using GlassFish in NetBeans, IntelliJ, and Eclipse – Part 2
- TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse
- Screencast #WS2: Invoking a Web service using NetBeans IDE
- GlassFish v2 supported in IntelliJ Web Services Plugin
I can’t wait for better support for generating clients for JAXWS. But in the meantime, the way I am doing it now works very well.
First I generated my client using the command line and the wsimport that is included in glassfish. Setting it up with the -p packagename -s src -d build and the URL for the wsdl. Running this from the work directory to the project I wanted to import it into. Refresh the project and everything was great.
So in order to integrate it, I simply created an external launcher, naming it “Generate Java For Web Service name” add in the executable for wsimport and then the parameters (as mentioned above). All in all I’d almost say its easier to regenerate this way than within Netbeans although the initial setup is a little more complicated.
Hope this helps!
Geoff
Comment by Geoff — July 20, 2007 @ 7:16 am
Geoff, glad to know you found another way as well! Can you provide more details on “its easier to regenerate this way than within Netbeans” ? In NetBeans regenerate is just a menu click.
Comment by Arun Gupta — July 20, 2007 @ 1:49 pm
You are so right, I’m sorry about that! Yes refreshing the web service couldn’t be easier (as is the case for most things in Netbeans!).
I was actually thinking of the Generation Wizard (which is still incredibly easy), where you have to enter the WSDL url and package name. This is why I was saying it was easier to click the external run button on Eclipse. I’m sorry about the confusion.
I love both products quite a bit. I started using Netbeans as soon as it started having all of the wonderful Java EE 5 treats and just started using Eclipse again now that 3.3 has come out.
I keep trying to figure out how I can make Eclipse more Netbeans like and Netbeans more Eclipse like I was bumbed when I couldn’t find anyway to get Eclipse to do the JAXWS client, thus I was very happy when I figured out this simple work around.
Thanks again!
Geoff
Comment by Geoff — July 20, 2007 @ 5:38 pm
Very cool! I’m glad you are liking NetBeans and hope you are enjoying all the screencasts. Let me know if you’d like to see something in NetBeans and Web services support.
Comment by Arun Gupta — July 20, 2007 @ 6:03 pm
The post is really good. Thanks. And…the next step ¿integrating Eclipse with openESB?.
I think that the ESB specification is the future natural context of SOA. Perhaps a good grafical designer for BPEL modules on eclipse is a good start.
Thanks again.
Comment by Antonio Muñiz — August 23, 2007 @ 7:05 am
Antonio, Have you checked the partners OpenESB directory at https://open-esb.dev.java.net/CommunityPartnerDirectory.html ? Particularly Bostech has an Eclipse plugin.
Comment by Arun Gupta — September 11, 2007 @ 11:17 am
Hi Arun,
This helps.
I was trying to figure out a way of adding authentication parameters at runtime to SOAP header through JAX-WS client.
Is it possible?
Currently , I have created Web-Service client using "drag-drop" functionality in Netbeans 6.0.
I need to add certain parameters in SOAP Header as I am getting SOAPFaultException back.
Thanks for your help.
Oh, i forgot to mention, i am newbie to web-service, so please forgive me if I am asking stupid questions.
Thanks
Tom
Comment by Tom Ethens — February 20, 2008 @ 2:56 pm
Tom, you can send additional SOAP headers as described at:
https://metro.dev.java.net/guide/SOAP_headers.html#Adding_SOAP_headers_when_sending_requests
Thanks,
-Arun
Comment by Arun Gupta — February 20, 2008 @ 4:43 pm
Hi Arun,
Thanks for your quick response.
I tried to manipulate my client as per the instructions on link , but still I am getting SoapFaultException back.
Question: How do we actually see during runtime the SOAP message that is going out in Netbeans 6.0
Thanks for your time.
Appreciate your help.
Cheers,
Tom
Comment by Tom Ethens — February 21, 2008 @ 11:41 am
Tom, You can view the SOAP messages going over the wire by using one of the logging properties defined at:
http://blogs.sun.com/arungupta/entry/totd_1_soap_messaging_logging
Please post your question on Metro forum (http://forums.java.net/jive/forum.jspa?forumID=46) for a broader audience.
Comment by Arun Gupta — February 21, 2008 @ 11:56 am
Thanks for your help, Arun.
I will do that.
Cheers,
Tom.
Comment by Anonymous — February 21, 2008 @ 12:55 pm
Hi Arun,
If iam given a wsdl file and ask to generate a webservice client prog how do i do that .Please help me with this I am using eclipse 3.2 and My eclipse 5.1 and axis2 this is my ,clients specification .Please help me ASAP
Comment by Arun K V — March 6, 2008 @ 4:19 am
Arun K V, You can use NetBeans and it’s in-built support for Metro for generating this client. For Eclipse & Axis, you need to ask the question on their forum.
Comment by Arun Gupta — March 6, 2008 @ 2:52 pm
Hi Arun,
Do you have any tutorial to invoke a external web service from a bpel process in netbeans?
Comment by Mithun — June 23, 2008 @ 8:48 am
Mithun,
A quick Google gave me the following links:
http://www.jcmartin.org/2006/05/24/1148489581214.html
http://weblogs.java.net/blog/kalali/archive/2007/05/a_scenario_base.html
http://weblogs.java.net/blog/kalali/archive/2007/05/a_scenario_base.html
Comment by Arun Gupta — June 23, 2008 @ 9:51 am
Can you point me to information as to how to start using GlassFish OpenESB with Eclipse? I’m using GlassFish Tools Bundle prelude v3 with Eclipse using Axis runtime. All is working well for PO Services. Would like to move into a “Hello World” example using OpenESB.
Thanx!
Comment by Lew Pearson — October 1, 2009 @ 1:36 pm