java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer

后端 未结 10 1425
名媛妹妹
名媛妹妹 2020-12-14 20:58

You may feel this is a duplicated question, but none of the questions with the same title solve my problems. I am using Jersey 2.0 creating a RESTful web service in Eclipse,

相关标签:
10条回答
  • 2020-12-14 21:53

    For me, the fix was doing this:

    Right click on Project -> Properties -> Java Build Path -> Libraries ->
    Add Library... -> Server Runtime -> Apache Tomcat v7.0 -> Finish
    

    Another step i did was to import stuff in Maven but it wasnt neccessary as it is running fine without it too.

    But here it is if it helps anyone

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2.1-b03</version>
            <scope>provided</scope>
        </dependency>
    

    putting servlet jars in WEB-INF/lib just did things more complicated as the Exception Message got more complicated and irrelevant

    EDIT: oh what also does help is to do an Update Project on your Maven Project.

    0 讨论(0)
  • 2020-12-14 21:54

    Add Jersey library to the build path under library

    0 讨论(0)
  • 2020-12-14 21:55

    Wait, you said you have a Jersey library called jersey, did you create a User Library and name it jersey? If so, try to copy your jersey jar files into WebContent -> WEB-INF -> lib.

    0 讨论(0)
  • 2020-12-14 21:56

    I guess this has already been answered, but just wanted to add an extra tip.

    For web projects in Eclipse, it is almost always advisable to manage dependencies with Maven. Use a Maven plugin like m2e. Once you add a dependency to your Maven project, it should automatically deploy those libraries to WEB-INF/lib. If it does not (for whatever reasons), you can explicit do so:

    1. Right-click on your project in Project Explorer
    2. Select Properties
    3. Select Deployment Assembly
    4. If Maven Dependencies is not one of the entries, the libraries were not added automatically, so we'll add them now
    5. Select Add
    6. Select Java Build Path Entries
    7. Select Maven Dependencies
    8. Click Finish

    This should add the libraries to WEB-INF/lib, although you'd still not see them in the Project Explorer view. But your ClassNotFoundException should go away now.

    0 讨论(0)
提交回复
热议问题