0

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?

Stefan S.
  • 3,950
  • 5
  • 25
  • 77
  • Probably the Java version you are using is not compatible (too new). Try to use an older version. You can have a look at [this](https://stackoverflow.com/a/52660446/2587435) to understand, though that is for Jersey 2.x. – Paul Samsotha Jul 15 '19 at 07:19
  • @PaulSamsotha Ah, but it's probably better to switch to Jersey 2.x right away. I wasn't aware of this version, since I get literally no search results for it searching for "Jersey". – Stefan S. Jul 15 '19 at 07:52
  • Yeah, if you're starting out, start with the latest version. Here are [the docs](https://jersey.github.io) – Paul Samsotha Jul 15 '19 at 09:12

0 Answers0