Intellij Rest服务项目 - java.lang.ArrayIndexOutOfBoundsException

时间:2016-07-13 11:17:40

标签: java rest intellij-idea jersey jax-rs

我在Intelli jidea上创建了一个Restful Web Service项目,其中包含由Ide创建的默认HelloWorld示例。

 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");
     }
 }

当我尝试运行它时出现此错误

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) 

我已经尝试过Jersey库的2.2版,1.2版和1.0版。 Jdk 1.8.0_91

2 个答案:

答案 0 :(得分:2)

它似乎是java 8的问题。有相同的异常,当我改变java版本使用我的JDK 7时,它停止了抱怨。

答案 1 :(得分:0)

我尝试了最新版本的jersey(1.19.4),它适用于JDK 8。 Maven依赖:

label: function () {
  // RED.nodes.getNode is not available here
  const myConfig = RED.nodes.getNode(this.my-config-node)
  return this.name || 'myConfig:' + (myConfig ? myConfig.myVar : '')
}