IntelliJ中基本的新RESTful项目无法运行,注释扫描失败?

时间:2014-06-21 17:39:43

标签: java-ee intellij-idea jersey intellij-13

我正在运行IntelliJ 13.1.3。我创建一个新项目,检查RESTful Web Service(2.2),选中Generate server code sample框,单击next,输入项目名称,然后单击finish。

我现在有一个带代码的示例项目。由于我没有改变任何内容并且它到目前为止都是自动生成的,所以我应该能够运行并让它运行。

可悲的是,这失败了。 IntelliJ找不到com.sun.jersey来从中导入任何东西,特别是示例代码使用的HttpServerFactory类。我发现this question似乎是同一个问题,并按照那里的说明进行操作。这是有效的,现在项目正在编译。

所以,我点击了运行,期待一些控制台输出,并且能够通过在我的浏览器中访问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

所有我设法找到这个问题的是this self-solved post,这表明某个地方有一个腐败的Java类会导致注释扫描失败,但是我已经检查了我的平台设置/ SDK并且看不到任何东西不合时宜,无论如何我正在进行全新的安装。

有关如何解决此问题的任何想法,或者为什么需要修复导入?

2 个答案:

答案 0 :(得分:4)

我遇到了在Java 8下运行的相同问题。在允许服务器运行的意义上,回归到Java 7“修复”它。

答案 1 :(得分:0)

将球衣升级到1.19应该这样做。