I don't want to use Tomcat, Jetty or an Java EE 6 container to offer REST services but the built in web server.
Ensure that you have Jersey's jersey-server.jar
in the classpath, then it's as simple as:
HttpServer server = HttpServerFactory.create("http://localhost:9998/");
server.start();
Pick whatever port you want to use.
For Jersey 2.x you will need jersey-container-jdk-http in your classpath. If you are using maven add this to your pom.xml
:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jdk-http</artifactId>
<version>2.9.1</version>
</dependency>
To start the server use this:
URI baseUri = UriBuilder.fromUri("http://localhost/").port(10000).build();
ResourceConfig resourceConfig=new ResourceConfig(WebService.class);
HttpServer httpServer=JdkHttpServerFactory.createHttpServer(baseUri, resourceConfig,true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With