Skip to content

Instantly share code, notes, and snippets.

@rjdkolb
Created November 4, 2013 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjdkolb/7301662 to your computer and use it in GitHub Desktop.
Save rjdkolb/7301662 to your computer and use it in GitHub Desktop.
How to spin up a restful webserver with jersey 1.x
import java.io.IOException;
import com.sun.jersey.api.container.httpserver.HttpServerFactory;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.net.httpserver.HttpServer;
public class RunRest {
static final String BASE_URI = "http://localhost:9999/rest/";
public static void main(String[] args) {
try {
ResourceConfig rc = new PackagesResourceConfig("org.openrap.rest");
HttpServer server = HttpServerFactory.create(BASE_URI, rc);
server.start();
System.out.println("Press Enter to stop the server. ");
System.in.read();
server.stop(0);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment