javajax-rs

Can I run a JAX-RS web service on com.sun.net.httpserver.HttpServer?


Can I run a simple webservice like this:

@Path("/rs/hello")
public class HelloWorldProgram {

    //path is default
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String sayHello() {
        return "Hello, World!";
    }

    @GET
    @Produces(MediaType.TEXT_XML)
    @Path("/xml")
    public String sayXMLHello() {
        return "<?xml version=\"1.0\"?>" + "<hello> Hello" + "</hello>";
    }
}

on the bundled with the JDK simple web server com.sun.net.httpserver.HttpServer ?


Solution

  • Yes, you can. Take a look at the "helloworld-pure-jax-rs" example of Jersey: https://github.com/jersey/jersey/tree/master/examples/helloworld-pure-jax-rs