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 FilesJavajdk1.8.0_05jrelibcharsets.jar
D:Program FilesJavajdk1.8.0_05jrelibdeploy.jar
D:Program FilesJavajdk1.8.0_05jrelibjavaws.jar
D:Program FilesJavajdk1.8.0_05jrelibjce.jar
D:Program FilesJavajdk1.8.0_05jrelibjfr.jar
D:Program FilesJavajdk1.8.0_05jrelibjfxswt.jar
D:Program FilesJavajdk1.8.0_05jrelibjsse.jar
D:Program FilesJavajdk1.8.0_05jrelibmanagement-agent.jar
D:Program FilesJavajdk1.8.0_05jrelibplugin.jar
D:Program FilesJavajdk1.8.0_05jrelibresources.jar
D:Program FilesJavajdk1.8.0_05jrelibrt.jar
D:Program FilesJavajdk1.8.0_05jrelibextaccess-bridge-64.jar
D:Program FilesJavajdk1.8.0_05jrelibextcldrdata.jar
D:Program FilesJavajdk1.8.0_05jrelibextdnsns.jar
D:Program FilesJavajdk1.8.0_05jrelibextjaccess.jar
D:Program FilesJavajdk1.8.0_05jrelibextjfxrt.jar
D:Program FilesJavajdk1.8.0_05jrelibextlocaledata.jar
D:Program FilesJavajdk1.8.0_05jrelibextnashorn.jar
D:Program FilesJavajdk1.8.0_05jrelibextsunec.jar
D:Program FilesJavajdk1.8.0_05jrelibextsunjce_provider.jar
D:Program FilesJavajdk1.8.0_05jrelibextsunmscapi.jar
D:Program FilesJavajdk1.8.0_05jrelibextsunpkcs11.jar
D:Program FilesJavajdk1.8.0_05jrelibextzipfs.jar
D:testtargetclasses
D:testlibjersey-container-servlet.jar
D:testlibjersey-container-servlet-core.jar
D:testlibjersey-client.jar
D:testlibjavax.ws.rs-api-2.0.jar
D:testlibjersey-common.jar
D:testlibjersey-server.jar
C:UsersDouglas.m2repositorycomsunjerseyjersey-server1.18.1jersey-server-1.18.1.jar
C:UsersDouglas.m2repositorycomsunjerseyjersey-core1.18.1jersey-core-1.18.1.jar
D:Program FilesJetBrainsIntelliJ IDEA 13.1.3libidea_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?
我在Java 8下运行的时候遇到了同样的问题。在允许服务器运行的意义上,回归到Java 7“固定”它。
升级泽西1.19应该做到这一点。
链接地址: http://www.djcxy.com/p/80134.html