2
respostas

Falha ao subir o servidor Grizzly no java 1.8

Boa tarde. Estou tendo este problema ao tentar subir o servidor Grizzly. Versão do java que estou usando: 1.8

Alguém pode dizer o que preciso fazer?

Grato

dez 17, 2019 5:10:38 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFORMAÇÕES: Initiating Jersey application, version Jersey: 2.5 2013-12-18 14:27:29...
Exception in thread "main" javax.ws.rs.ProcessingException: IOException thrown when trying to start grizzly server
    at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:276)
    at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:110)
    at br.com.alura.loja.Servidor.main(Servidor.java:14)
Caused by: java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
    at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
    at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bindToChannelAndAddress(TCPNIOBindingHandler.java:131)
    at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bind(TCPNIOBindingHandler.java:87)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:449)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:429)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:420)
    at org.glassfish.grizzly.http.server.NetworkListener.start(NetworkListener.java:658)
    at org.glassfish.grizzly.http.server.HttpServer.start(HttpServer.java:264)
    at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:274)
    ... 2 more
2 respostas

Você deve ter outro processo que está utilizando a mesma porta do seu servidor. Verifique se existe outro servidor que se utilize da mesma porta ou se outro aplicativo está utilizando a porta. Se você não quiser finalizar o serviço que está utilizando a porta do seu Grizzly, pode então configurar o seu Grizzly para utilizar outra porta.

Prezado Carlos, boa tarde.

Não sei lhe dizer porque, mas fiz as mudanças abaixo e funcionou, inclusive na porta 8080, que em tese, está ocupada.

public class Servidor {
    public static void main(String[] args) throws IOException {
        ResourceConfig config = new ResourceConfig().packages("br.com.alura.loja");
//        URI uri = URI.create("http://localhost:8081/");        
        HttpServer server = HttpServer.createSimpleServer("/",8080);
//        HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri, config);
        System.out.println("Servidor rodando");
        System.in.read();
        server.stop();
    }
}

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software