Running Jersey on Grizzly on Linux and Windows

限于喜欢 提交于 2019-12-05 05:42:33

I am not using Maven. As of Today (26 July, 2013) I include the following jars to work with standalone grizzly server from my eclipse (Project | Run - no web.xml etc.)

  • grizzly-framework-2.3.4.jar
  • grizzly-http-2.3.4.jar
  • grizzly-http-server-2.3.4.jar
  • jersey-container-grizzly2-http-2.0.jar

To download the files : head over to http://grizzly.java.net/dependencies.html and look for non maven developers files. The console server looks like

package test;

import java.io.IOException;
import java.net.URI;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.grizzly.http.server.HttpServer;


public class GrizzlyServer {

    private static final URI BASE_URI = URI.create("http://localhost:9090/service/");

    @SuppressWarnings("deprecation")
    public static void main(String[] args) throws IOException {


            final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp());
            System.out.println(String.format("Application started.%nHit enter to stop it..."));
            System.in.read();
            server.stop();
    }

    public static ResourceConfig createApp() {
        ResourceConfig rc = new ResourceConfig()
        .packages("test")
        .register(JacksonFeature.class);

        return rc;

    }

}

Ok, so I now own a mac and figured I would try the same procedure there. Not to my surprise, I ran into the same problem that I did in the linux environment. I had a co-worker try the same procedure on his machine, but it worked fine for him. The only thing that I noticed different when I did it was I got the following popup:

I had always just clicked ok. Since my co-worker never got the popup, I tried it again, this time clicking cancel. That seems to have done the trick.

user1626945

You need to use a maven transformer to ensure that the service files are merged properly. See Grizzly and Jersey standalone jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!