我正在运行 IntelliJ 13.1.3。我新建一个项目,勾选 RESTful Web Service (2.2),勾选 Generate server code sample,点击下一步,输入项目名称,点击完成。
我现在有一个带有代码的示例项目。因为我什么都没做,而且到目前为止都是自动生成的,所以我应该可以点击运行并让它工作。
可悲的是,这失败了。IntelliJ 找不到 com.sun.jersey 以从中导入任何内容,尤其是示例代码使用的 HttpServerFactory 类。我发现这个问题似乎是同一个问题,并按照那里的说明进行操作。这行得通,项目现在可以编译。
所以,我点击运行,期待一些控制台输出和通过在我的浏览器中访问 localhost 来获得“Hello World”的能力。相反,我得到一个异常的堆栈跟踪。控制台输出为:
Jun 21, 2014 10:24:34 AM com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Scanning for root resource and provider classes in the paths:
D:\Program Files\Java\jdk1.8.0_05\jre\lib\charsets.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\deploy.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\javaws.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\jce.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\jfr.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\jfxswt.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\jsse.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\management-agent.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\plugin.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\resources.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\rt.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\access-bridge-64.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\cldrdata.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\dnsns.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\jaccess.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\jfxrt.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\localedata.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\nashorn.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\sunec.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\sunjce_provider.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\sunmscapi.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\sunpkcs11.jar
D:\Program Files\Java\jdk1.8.0_05\jre\lib\ext\zipfs.jar
D:\test\target\classes
D:\test\lib\jersey-container-servlet.jar
D:\test\lib\jersey-container-servlet-core.jar
D:\test\lib\jersey-client.jar
D:\test\lib\javax.ws.rs-api-2.0.jar
D:\test\lib\jersey-common.jar
D:\test\lib\jersey-server.jar
C:\Users\Douglas\.m2\repository\com\sun\jersey\jersey-server\1.18.1\jersey-server-1.18.1.jar
C:\Users\Douglas\.m2\repository\com\sun\jersey\jersey-core\1.18.1\jersey-core-1.18.1.jar
D:\Program Files\JetBrains\IntelliJ IDEA 13.1.3\lib\idea_rt.jar
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 39168
at jersey.repackaged.org.objectweb.asm.ClassReader.readClass(ClassReader.java:1976)
at jersey.repackaged.org.objectweb.asm.ClassReader.accept(ClassReader.java:464)
at jersey.repackaged.org.objectweb.asm.ClassReader.accept(ClassReader.java:420)
at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138)
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:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 1
我在这个问题上找到的只是这个自我解决的帖子,它表明某处有一个损坏的 Java 类导致注释扫描失败,但我检查了我的平台设置/SDK,没有任何东西看起来不合适,而且无论如何我都在运行全新的安装。
关于如何解决这个问题的任何想法,或者为什么需要修复导入?