MessageBodyWriter not found vogella tutorial

后端 未结 3 823
孤街浪徒
孤街浪徒 2021-01-19 14:44

I am attempting to recreate the most excellent vogella tutorial for create REST with java, JAX-RS and Jersey.

I\'m using eclipse Kepler with Java-EE perspective, to

3条回答
  •  醉梦人生
    2021-01-19 15:26

    My understanding is that the jaxrs-ri 2.13 bundle includes everything required including dependencies to let me do this - and that I don't need to add any kind of JSON provider.

    That's actually incorrect. As stated at the Jersey User Guide 8.1. JSON

    Jersey JSON support comes as a set of extension modules where each of these modules contains an implementation of a Feature that needs to be registered into your Configurable instance (client/server). There are multiple frameworks that provide support for JSON processing and/or JSON-to-Java binding. The modules listed below provide support for JSON representations by integrating the individual JSON frameworks into Jersey. At present, Jersey integrates with the following modules to provide JSON support:

    • MOXy - JSON binding support via MOXy is a default and preferred way of supporting JSON binding in your Jersey applications since Jersey 2.0. When JSON MOXy module is on the class-path, Jersey will automatically discover the module and seamlessly enable JSON binding support via MOXy in your applications. (See Section 4.3, “Auto-Discoverable Features”.)

    • Among a few others

    So the main Jersey download doesn't come with these extra modules. We need to obtain them separately. That being said, the easiest way to get the required jersey-media-moxy is through Maven.

    
        org.glassfish.jersey.media
        jersey-media-moxy
        2.13
    
    

    If you're not using Maven (which looking through the tutorial, it doesn't), you're going to have to do some searching for the dependencies. The jersey-media-moxy artifact has 16 dependencies, but Fortunately, most are contained within the Jersey distribution. So after filtering out what was already included in the Jersey distro, these are the remaining jars you will have to find on your own (I just created a User Library to test out)

    enter image description here

    Adding these dependencies will get the example up and running. Tested and works as expected after adding these.

    Now you have Eclipse, which I assume came with the Maven (m2e) plugin. So maybe the easiest way to get these dependencies is to create a new Maven project, and add the dependency shown above. After you build the project, maven should download all the extra dependencies into your local Maven Repo. Just grab them from there for your main project.


    Other Resources/Notes

    • Jersey User Guide
    • I would download the Jersey Example package, which is more up to date then the tutorial you are using.
    • If you don't know Maven, I would strongly suggest learning at least the basic of dependency management, and let the build framework grab all the dependencies for you. Also all the examples in the examples package uses Maven, so it would help to know the basics.

提交回复
热议问题