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

标签 java rest intellij-idea jersey jax-rs

我使用 Ide 创建的默认 HelloWorld 示例在 Intelli jidea 上创建了一个 Restful Web 服务项目。

 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

最佳答案

这似乎是 java 8 的问题。有同样的异常,当我更改 java 版本以使用我的 JDK 7 时,它不再提示。

关于java - Intellij Rest 服务项目 - java.lang.ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38350187/

相关文章:

Java:使用泛型扩展类

java - 通过servlet从数据库获取信息

java - 为什么Spring MVC GET方法不通过json值设置POJO类?

java - Spring 休息模板

android - 无法启动 Gauge Intellij 插件

java - Intellij 中奇怪的 Javadoc 包装

java - 如何根据用户插入的月数计算预计日期?

java - Jersey/JAX-RS ExceptionMapper MySQL

java - 领域模型和剩余表示的解耦

intellij-idea - IntelliJ 和 xDebug - xdebug.file_link_format