How to run jersey with embedded web server with Java SE 6?

I do not want to use Tomcat, Jetty, or the Java EE 6 container to provide REST services, but an embedded web server.

+6
java jersey java-6
source share
2 answers

Make sure you have jersey jersey-server.jar in the classpath, then this is simple:

 HttpServer server = HttpServerFactory.create("http://localhost:9998/"); server.start(); 

Select any port you want to use.

+5
source share

For Jersey 2.x you will need jersey-container-jdk-http in your class path. 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); 
0
source share

All Articles