launching 3rd party servlets using jetty for unit testing


Apache Maven

  <!-- I'm not sure this is the minimum dependency -->


    private static final PORT;

    static {
        PORT = ThreadLocalRandom.current().nextInt(1024, 65536);

    private static Server SERVER;

    public static void startServer() throws Exception {
        SERVER = new Server(PORT);
        final ServletHandler handler = new ServletHandler();
        handler.addServletWithMapping(SomeServlet.class, "/some");

    public static void stopServer() throws Exception {
        SERVER = null;

    public void test() throws MalformedURLException {
        final URL url = new URL("http://localhost:" + PORT + "/some");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s