Search code examples
jerseyjersey-2.0

Jersey: org.glassfish.jersey.server.mvc cannot be resolved


I want to use Jersey MVC in my project. I've never used Jersey MVC before.

I'm working in:

  • Eclipse (Version: Neon.1a Release (4.6.1))

, using:

  • Jersey 2.25.1

  • Apache Tomcat 7.0.76.


Here's the example I'm trying to run:

Hello.java

enter image description here

MyApp.java

enter image description here

NewFile.jsp

enter image description here

I have downloaded jersey 2.25.1 from here

enter image description here

and added all jar files in

enter image description here

Here's how I call my web service:

enter image description here


The underlined import line tells:

enter image description here

So this is the problem I want to solve.


Because I have not found any information related to this problem I searched for jersey mvc related jar file. I found it here.

I added jersey-mvc-2.25.1.jar in lib folder.

So the package (and Viewable class) was found.

But when I run on server I get the following stack trace:

enter image description here

enter image description here

enter image description here

Thank you in advance.


Solution

  • Here's how I solved the problem:

    First of all, jersey-mvc-2.25.1.jar is not enough to use MVC Jersey.

    I downloaded the file jersey-mvc-jsp-2.25.jar.

    I put both jars in lib

    enter image description here


    Now here's my working basic example:

    The structure of my project is:

    enter image description here

    The source code is:

    MyApp.java

    enter image description here

    Hello.java enter image description here

    NewFile.jsp

    enter image description here

    To see the result I started the Tomcat server, then:

    enter image description here

    It worked!


    Related to classpath/buildpath setting in Eclipse:

    I didn't Add Jars (jersey-mvc-2.5.1.jar and jersey-mvc-2.5.1.jar) in classpath or buildpath. It worked anyway.


    What really helped to understand all this is:

    Absolute vs. Relative template reference

    Annotations