4

I am really really having hard time to create simple "Hello World" Web Service in Java. If you exclude several mobile Android mobile apps I have done, I am pretty new to Java environment.

First I tried Axis2 and that simply doesn't work out of the box. Fresh installation of Eclipse, Tomcat 6.0 and Axis2. Tried sample test app and it failed miserably. You can read about it here. My conclusion is that Axis2 simply doesn't work (maybe it used to work). I will try to go back to install older versions, maybe one will magically start working. I have to modify some old project at work that was using Axis2, so that's why I have to stick with it. I would hate to have to migrate to some other tool.

Then I ran on Oracle article Getting Started with JAX-RPC and I was thinking, cool, let's try that. Well, I just managed to get pissed off. After getting half way through the article and trying to write some simple test web service I realized that their code examples are poorly written. Missing brackets, wrong references, missing explanations, etc...

First of all, an interface should extend not implement. Am I right?

public interface SunRegPort implements java.rmi.Remote {

Also, this doesn't exist:

import java.xml.rpc.server.ServiceLifecycle;

But this does:

import javax.xml.rpc.server.ServiceLifecycle;

Well, I don't feel competent to criticize too much (cause of my level of knowledge about this subject of course), but after all I am suspicious that this article is complete JUNK and therefore I am not able to follow it.

Please somebody tell me that I am wrong and if anybody has some advice or link to some How-To page that talks about web services, I would appreciate.

Thanks.

Community
  • 1
  • 1
bobetko
  • 5,019
  • 14
  • 58
  • 85
  • interfaces extend other interfaces.Only classes implement interfaces. Take a look at Jax-WS .. http://jax-ws.java.net/ – Kal Aug 18 '11 at 16:30
  • Whenever you find something on the web you should always check the date it was written. I did check your example: it's from 2002! In computer years that's way back in the stone age. What they wrote was probably valid back in the days. You're not supposed to explicitly use RPC/RMI anymore. – toto2 Aug 18 '11 at 17:06

5 Answers5

3

The terminology Web Services is pretty vague. In Java, the modern and reasonably easy way to do this is by annotating classes. I would recommend that first, you decide whether you want to implement:

  • SOAP Web Services -> look at JAX-WS
  • REST Web Services -> look at JAX-RS

Once you have chosen the "type" of Web Services, choose the library that implements the specification.

The Wikipedia entries list a few of these implementations. Apache CXF (complete but a beast), Jersey (popular) and Restlet are very common choices. I personally like the JBoss implementations as well for JAX-WS.

For JAX-WS with Apache CXF, here is a quick start tutorial that looks pretty good (untested)

For JAX-RS with Jersey, try this

Unless you have strong reasons to do otherwise (for instance you need to call an existing system), use REST which is simpler and leaner.

Bruno Grieder
  • 28,128
  • 8
  • 69
  • 101
  • That [quick start tutorial](http://blog.sortedset.com/step-by-step-web-services-with-tomcat-tomee-apache-cxf-eclipse/) seems to have been taken down. – Varun Gawande May 20 '21 at 07:25
1

I would recommend you to check out the CXF project by apache. It's quite easy to use and should help you to set up a webservice.

There is a nice guide to Hello world set up.

http://cxf.apache.org/docs/a-simple-jax-ws-service.html

hequ
  • 761
  • 6
  • 14
0

Web Services are most widely implemented examples of Service Oriented Architecture (SOA). A service contract is defined with the help of SOAP and Web Service Definition Language (WSDL) and that is published for other applications to use.

In this article we will see how we can create web service and web service client in java.

http://www.opencodez.com/java/how-to-build-and-deploy-web-service-and-client-in-java.htm

0

If you're still interested in giving Tomcat a shot, here is a tutorial on youtube of making a very basic "Hello world" example using Eclipse. It leaves a lot to learn; but it looks like it will at least get you started.

FYI, the version of Eclipse used is slightly outdated. So some of the menu options may not be exactly the same:

http://www.youtube.com/watch?v=EOkN5IPoJVs

Also, the meaning of "Web Service" can be subjective. So, to be specific; this just shows you how to get a basic HTTP endpoint started on your local machine.

Dave
  • 6,141
  • 2
  • 38
  • 65
0

If you are not tied to Eclipse, give NetBeans a shot. I think it's much better for Web Services in Java.

DaveFar
  • 7,078
  • 4
  • 50
  • 90