Douglas
Douglas

Reputation: 5087

Basic new RESTful project in IntelliJ fails to run, annotation scan failure?

I'm running IntelliJ 13.1.3. I create a new project, check RESTful Web Service (2.2), check the box for Generate server code sample, click next, enter a project name, and click finish.

I now have a sample project with code. As I have changed nothing and it's all automatically generated so far, I should be able to just hit run and have it work.

Sadly, this fails. IntelliJ can't find com.sun.jersey to import anything from in, in particular the HttpServerFactory class that the sample code uses. I found this question that seems to be the same problem, and follow the instructions there. That works, and the project now compiles.

So, I hit run, expecting some console output and the ability to get "Hello World" by visiting localhost in my browser. Instead, I get a stack trace on an exception. Console output is:

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

All I've managed to find on this problem is this self-solved post, which suggests that there's a corrupt Java class somewhere that's causing an annotation scan to fail, but I've checked my Platform Settings/SDKs and nothing looks out of place, and I'm running on a completely fresh install anyway.

Any ideas for how to fix this, or why the import needed to be fixed?

Upvotes: 7

Views: 1761

Answers (2)

Yamcha
Yamcha

Reputation: 1334

upgrading jersey to 1.19 should do it.

Upvotes: 0

Maurice Naftalin
Maurice Naftalin

Reputation: 10533

I had the same problem running under Java 8. Regressing to Java 7 "fixed" it, in the sense of allowing the server to run.

Upvotes: 4

Related Questions