Tuesday, February 4, 2014

Jersey and Maven Jetty plugin

Recently I ran into an issue working with Jersey and the Jetty Maven plugin. The application is built for Glassfish so I had marked the Jersey libraries as provided. In the Maven Jetty plugin configuration I put Jersey in the configuration for the dependency but when I went to start the server I got the following error:

2014-02-04 10:12:25.320:WARN:oejut.
QueuedThreadPool:qtp1736120767-24:
java.lang.IncompatibleClassChangeError: org/eclipse/jetty/annotations/AnnotationParser$MyClassVisitor
    at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:971)
    at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry(AnnotationParser.java:953)
    at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:906)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:828)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:111)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:472)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:744)
 
After a bit of digging around I found that changing the Jersey dependencies to compile resolved this issue. I figure I must be doing something bad to the Jetty class loader where by loading in the container's classloader is breaking something.

In the end I settled for setting the dependency scope to 'test' and adding the test classpath on the Jetty classpath. This is not ideal as it doesn't really express the dependencies properly of the application.

Hopefully this helps someone else who runs into this issue!