Quickly implement, deploy a Webservice in Java

这一生的挚爱 提交于 2019-12-04 10:09:53
Pascal Thivent

What is today the quickest way to implement this in Java? I thoughted AXIS+Tomcat. Maybe is there any other newest library?

Yes, there is a much better way. Forget Axis and go for a JAX-WS stack such as JAX-WS RI (which is included in Java 6) or Apache CXF. Here is the usual HelloWorld service with a test method using the built-in HTTP server of the JDK:

package hello;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class Hello {
    @WebMethod
    public String sayHello(String name) {
        return "Hello, " + name + ".";
    }

    public static void main(String[] args) {
        Endpoint.publish("http://localhost:8080/WS/Hello", new Hello());
    }
}

Just run the main method and you're ready to play with the web service.

Of course, you'll want to deploy your web service on a real container for production use. You could go with GlassFish and just deploy your service (GlassFish bundles a JAX-WS runtime). Or you could pick Jetty or Tomcat and install the chosen runtime on it (JAX-WS RI or Apache CXF). Refer to their respective instructions.

Resources

Related question

there is also project "Jersey" the JSR-311 (JAX-RS) reference implementation. A Framework for Web Services implementing the REST principles, which in my opinion modern Web Services should adhere to. It got lots of tutorials on the web to be found.

Miklos Csuka

Apache Axis2, Apache CXF or Glassfish Metro 2.0 are all pretty up to date and will provide what you need. Spring-WS is probably easier to use than the previous 3, but only if you're already building in the Spring framework. For comparison see:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!