ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

前端 未结 3 991
旧巷少年郎
旧巷少年郎 2021-01-23 12:24

Hi Guys i am new to maven and webapps, so please bear with me. I have gone through most of the solutions in stack overflow like java.lang.ClassNotFoundException: com.sun.jersey

3条回答
  •  孤独总比滥情好
    2021-01-23 13:22

    So a couple things. First the problem with the ClassNotFoundExcetion. The class is in the jersey-servlet jar. Looking inside the built .war file all the jars are build to the war. So if you deployed the war manually it should work.

    This is a problem I see a lot with Eclipse users. I don't know if you are using Eclipse, what I have come to figure out is that, in the problem cases, Eclipse doesn't deploy the actual war to the server but creates an internal instance of the server and deploys the project artifacts instead of the actual war. In which case it doesn't load the jars.

    As a sanity check, you can add this jetty-maven-plugin. I use it all the time for development

    
        
            org.eclipse.jetty
            jetty-maven-plugin
            9.2.6.v20141205
        
        ...
    
    

    Then from the command line, you can run mvn jetty:run. This will deploy your app to an embedded Jetty instance created by Maven. I tested with your project it and works fine.

    The second thing is the dependencies. You need to decide what version of Jersey you want to user, a 1.x version or a 2.x version. Which ever you choose, you should get rid of all the other version artifacts.

    For your current project, assuming you wan to use Jersey 1.x, you should get rid of these two in your current project.

    
        org.glassfish.jersey.containers
        jersey-container-servlet
        2.0
    
    
        org.glassfish.jersey.core
        jersey-client
        2.0
    
    

    Removing those two and running with the Jetty plugin should work fine. As far as trying to run it from the IDE, I am not sure how to solve that problem.

提交回复
热议问题