Запуск Джерси на Grizzly в Linux и Windows

Я родом из Windows.NET,но я пытаюсь расширить свой опыт, и поэтому взял несколько проектов Java. В настоящее время я пытаюсь создать REST API, поэтому я решил пройтись по Джерси здесь :http://jersey.java.net/nonav/documentation/latest/getting-started.html

. Мне удалось заставить проект Hello World нормально работать в Windows (с использованием NetBeans и Maven ), однако, когда я снова пытаюсь сделать то же самое в Ubuntu (, используя NetBeans и Maven ), я получаю следующая ошибка:

Starting grizzly...
Aug 09, 2012 11:27:46 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  com.javarest.javarest2
Aug 09, 2012 11:27:47 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class com.javarest.javarest2.HelloWorldResource
Aug 09, 2012 11:27:47 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Exception in thread "main" java.lang.IllegalArgumentException: No container provider supports the type class org.glassfish.grizzly.http.server.HttpHandler
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:196)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:134)
    at com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpServer(GrizzlyServerFactory.java:242)
    at Main.startServer(Main.java:25)
    at Main.main(Main.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)

Я просмотрел эту публикацию:Автономный jar-файл Grizzly and Jersey и изменил мой pom.xml, чтобы иметь раздел сборки, который у него был, но я все еще получаю ту же ошибку. Код, который у меня есть, взят прямо из примера, но я опубликую его здесь:

HelloWorldResource.java:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.javarest.javarest2;

import javax.ws.rs.*;

/**
 *
 * @author ryan
 */
// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {

    // The Java method will process HTTP GET requests
    @GET
    // The Java method will produce content identified by the MIME Media
    // type "text/plain"
    @Produces("text/plain")
    public String getClichedMessage() {
        // Return some cliched textual content
        return "Hello World";
    }
}

Main.java

import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
import com.sun.jersey.api.core.DefaultResourceConfig;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import org.glassfish.grizzly.http.server.HttpServer;

import javax.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class Main {

    private static URI getBaseURI() {
        return UriBuilder.fromUri("http://localhost/").port(9998).build();
    }
    public static final URI BASE_URI = getBaseURI();

    protected static HttpServer startServer() throws IOException {
        System.out.println("Starting grizzly...");
        //ResourceConfig rc = new PackagesResourceConfig("com.sun.jersey.samples.helloworld.resources");
        ResourceConfig rc = new PackagesResourceConfig("com.javarest.javarest2");
        return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
    }

    public static void main(String[] args) throws IOException {
        HttpServer httpServer = startServer();
        System.out.println(String.format("Jersey app started with WADL available at "
                + "%sapplication.wadl\nTry out %shelloworld\nHit enter to stop it...",
                BASE_URI, BASE_URI));
        System.in.read();
        httpServer.stop();
    }
}

pom.xml:


    4.0.0

    com.javarest
    JavaREST2
    1.0-SNAPSHOT
    jar

    JavaREST2
    http://maven.apache.org

    
        UTF-8
    

    
        
            junit
            junit
            3.8.1
            test
        
        
            com.sun.jersey
            jersey-server
            1.8
        
        
            com.sun.jersey
            jersey-grizzly2
            1.13
        
        
            com.sun.jersey
            jersey-atom
            1.8
        
        
            com.sun.jersey
            jersey-json
            1.8
        
        
            com.sun.jersey
            jersey-core
            1.8
        
        
            com.sun.jersey
            jersey-client
            1.8
        
        
            com.sun.jersey.contribs
            jersey-atom-abdera
            1.8
        
        
            com.sun.jersey.contribs
            jersey-apache-client
            1.8
        
        
            com.sun.jersey.contribs
            jersey-spring
            1.8
        
        
            com.sun.jersey.contribs
            jersey-multipart
            1.8
        
        
            com.sun.jersey.contribs
            jersey-guice
            1.8
        
        
            com.sun.jersey.contribs
            jersey-simple-server
            1.8
        
        
            com.sun.jersey.contribs.jersey-oauth
            oauth-client
            1.8
        
        
            com.sun.jersey.contribs.jersey-oauth
            oauth-server
            1.8
        
        
            com.sun.jersey.contribs.jersey-oauth
            oauth-signature
            1.8
        
    

    
        
            
                org.apache.maven.plugins
                maven-shade-plugin
                1.5
                
                    
                        
                        
                            
                                com.javarest.javarest2.Main
                                1
                            
                        
                    
                
                
                    
                        package
                        
                            shade
                        
                    
                
            
        
    

7
задан Community 23 May 2017 в 12:09
поделиться