I want to start up a REST webservice using Jersey. Multiple tutorials stated that this is the way to go:
ResourceConfig resourceConfig = new PackagesResourceConfig(TestSystem.class.getPackageName());
HttpServer server = HttpServerFactory.create("http://localhost:8080/rest", resourceConfig);
server.start();
With a declaration of
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19.4</version>
</dependency>
However I get:
java.lang.IllegalArgumentException
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:170)
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:153)
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:424)
at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138)
at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner$1.f(FileSchemeScanner.java:86)
at com.sun.jersey.core.util.Closing.f(Closing.java:71)
at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:83)
at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scan(FileSchemeScanner.java:71)
at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:226)
at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:142)
(Even when I don't use the resourceConfig
.)
Naturally my first instinct was that something must be wrong with Jersey, so I tried 1.18.1:
java.lang.ArrayIndexOutOfBoundsException: Index 52264 out of bounds for length 287
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)
For everything above 1.19 I get the first exception, everything below it's the second one. So maybe something is wrong with my webservice:
@ApplicationPath(TestSystem.URL)
public class TestSystem extends Application {
public static final String URL = "/testsystem/";
}
@Path(HelloWorldEndpoint.URL)
public class HelloWorldEndpoint {
public static final String URL = "hello";
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/")
public String greet() {
return "Hello World!";
}
}
How do I start my REST webservice using Jersey?