3
respostas

Migrei esse projeto para o meven

estou tentando migrar o projeto para o maven porém estar ocorrendo o seguinte erro quando tento inicializar o servidor.

Exception in thread "main" java.lang.NoSuchFieldError: INCLUDE_ALL
    at org.glassfish.jersey.server.ResourceConfig$State.<init>(ResourceConfig.java:111)
    at org.glassfish.jersey.server.ResourceConfig.<init>(ResourceConfig.java:353)
    at br.com.loja.api.Servidor.main(Servidor.java:14)

Segue dependencias

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet-core -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.29.1</version>
        </dependency>
        <!-- Estrutura do servidor HTTP -->
        <dependency>
            <groupId>org.glassfish.grizzly</groupId>
            <artifactId>grizzly-http-server</artifactId>
            <version>2.4.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-grizzly2-http -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
            <version>2.0-m05-2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-grizzly2-http -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
            <version>2.30.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream -->
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.11.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
            <version>2.28</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.17</version>
        </dependency>
    </dependencies>
3 respostas

Código do Servidor.java

package br.com.loja.api;


import java.io.IOException;
import java.net.URI;

import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;

public class Servidor {

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

    public static HttpServer inicializaServidor() {
        ResourceConfig config = new ResourceConfig().packages("br.com.loja.api");
        URI uri = URI.create("http://localhost:8080/");
        HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri, config);
        return server;
    }
}

Erro parou de ocorrer, o que foi feito ? acredite absolutamente nada de repende funcionou kkkk

set 12, 2020 1:37:41 AM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:8080]
set 12, 2020 1:37:41 AM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Servidor rodando

Porém agora ocorre um erro ao chamar a URL http://localhost:8081/carrinhos/1

Alterei a porta para 8081

org.glassfish.jersey.server.ContainerRequest.<init>(Ljava/net/URI;Ljava/net/URI;Ljava/lang/String;Ljavax/ws/rs/core/SecurityContext;Lorg/glassfish/jersey/internal/PropertiesDelegate;Ljavax/ws/rs/core/Configuration;)V
     1: org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:345)
     2: org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:224)
     3: org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
     4: org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
     5: java.base/java.lang.Thread.run(Thread.java:834)
Please see the log for more detail.