2016-07-13 6 views
1

Ich habe ein REST-konformes Web Service-Projekt auf Intelli jidea mit der Standard Hello World Probe, die von Ide erstellt wurde.Intellij Rast Service Project - java.lang.ArrayIndexOutOfBoundsException

package example; 
import com.sun.net.httpserver.HttpServer; 
import com.sun.jersey.api.container.httpserver.HttpServerFactory; 
import java.io.IOException; 

import javax.ws.rs.GET; 
import javax.ws.rs.Produces; 
import javax.ws.rs.Path; 

/** 
    * Created by UNAL on 12.07.2016. 
    */ 
// The Java class will be hosted at the URI path "/helloworld" 
@Path("/helloworld") 
public class HelloWorld { 
    // 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"; 
    } 

    public static void main(String[] args) throws IOException { 
     HttpServer server = HttpServerFactory.create("http://localhost:9998/"); 
     server.start(); 

     System.out.println("Server running"); 
     System.out.println("Visit: http://localhost:9998/helloworld"); 
     System.out.println("Hit return to stop..."); 
     System.in.read(); 
     System.out.println("Stopping server"); 
     server.stop(0); 
     System.out.println("Server stopped"); 
    } 
} 

Wenn ich versuche, es zu laufen ich diese Fehlermeldung bekam

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 256 
at org.objectweb.asm.ClassReader.readClass(Unknown Source) 
at org.objectweb.asm.ClassReader.accept(Unknown Source) 
at org.objectweb.asm.ClassReader.accept(Unknown Source) 
at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:133) 
at com.sun.jersey.core.spi.scanning.JarFileScanner.scan(JarFileScanner.java:97) 
at com.sun.jersey.core.spi.scanning.JarFileScanner$1.f(JarFileScanner.java:74) 
at com.sun.jersey.core.util.Closing.f(Closing.java:71) 
at com.sun.jersey.core.spi.scanning.JarFileScanner.scan(JarFileScanner.java:71) 
at com.sun.jersey.core.spi.scanning.FilesScanner.scan(FilesScanner.java:83) 
at com.sun.jersey.core.spi.scanning.FilesScanner.scan(FilesScanner.java:74) 
at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80) 
at com.sun.jersey.api.core.ClasspathResourceConfig.init(ClasspathResourceConfig.java:119) 
at com.sun.jersey.api.core.ClasspathResourceConfig.<init>(ClasspathResourceConfig.java:101) 
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:263) 
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:246) 
at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:117) 
at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:92) 
at example.HelloWorld.main(HelloWorld.java:26) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 

Ich habe bereits versucht, Version 2.2, 1.2 und 1.0 von Jersey-Bibliotheken. Jdk 1.8.0_91

+0

bitte die neueren Jersey-Bibliotheken verwenden und den neuen Code schreiben. Das ist wirklich alt. Ich denke nicht, dass es etwas mit Jidea zu tun hat. – Apostolos

+0

neue Versionen von Jersey enthält keine HttpServerFactory Klasse. Weißt du, wie können wir den Code mit dem neuesten Jersey generieren? – amlelanu

Antwort

2

es scheint ein Problem mit Java 8. hatte die gleiche Ausnahme und als ich Java-Version geändert, um mein JDK 7 zu verwenden, hörte es auf sich zu beschweren.

+0

ich habe jetzt neueste Version von IntelliJ IDEA installiert. Das Ergebnis ist das gleiche. Ich werde uns JDK 7 versuchen, wie du gesagt hast. – amlelanu

+1

hat das selbe gemacht wie du und das hat für mich funktioniert. gleichen Fehler mit JDK 8, Fehler mit JDK 7. – Apostolos

+0

@unalelma gegangen hat es funktioniert? – Apostolos

0

Ich habe versucht, neueste Version von Jersey (1.19.4) und es funktioniert mit JDK 8. Maven Abhängigkeit:

<dependency> 
    <groupId>com.sun.jersey</groupId> 
    <artifactId>jersey-server</artifactId> 
    <version>1.19.4</version> 
</dependency>