Embedded jetty & jersey, works with Jersey 2.7, ex

2019-09-03 15:49发布

问题:

I'm trying the examples on:

  • How to embed Jetty and Jersey into my Java application
  • https://nikolaygrozev.wordpress.com/2014/10/16/rest-with-embedded-jetty-and-jersey-in-a-single-jar-step-by-step

If I run this with Jersey 2.7 (and Jetty 9.2.5.v20141112), it works. If I update Jersey to 2.9 (or 2.14), it fails on startup with:

 WARN 2015-01-18 17:02:13,076 e.jetty.util.component.AbstractLifeCycle:212  - FAILED org.eclipse.jetty.server.Server@1741055a: java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
    at org.glassfish.jersey.moxy.json.MoxyJsonFeature.configure(MoxyJsonFeature.java:67)
    at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:709)
    at org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:639)
    at org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:809)
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:388)
    at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:163)
    at org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:323)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
...
...

Does anybody have any idea how to change the code of the listed examples (or maybe my maven dependencies?) so that this works on 2.9/2.14?

Maarten

回答1:

OK, the request to add my full POM pointed me to the issue: I used a property to specify the version of the Jersey components, except for the jersey-media-moxy dependency, which I had hardcode to 2.7 :( My bad, sorry all...