ClassNotFoundException when starting tomcat

前端 未结 12 2162
孤城傲影
孤城傲影 2020-12-14 07:38

I\'m trying to make a REST web service.

My project looks like :

\"enter

<
相关标签:
12条回答
  • 2020-12-14 08:21

    I have encountered the same issue. I was using Version 1.12.

    I could not find the class com.sun.jersey.spi.container.servlet.ServletContainer in the "jersey-server-1.12.jar" or "jersey-core-1.12.jar" as suggested in some other forums.

    You can easily check this in Eclipse, when you add it to the Build Path and notice that you do not have that class in the above mentioned jar files.

    I searched around and found the following:

    It looks like the class com.sun.jersey.spi.container.servlet.ServletContainer is in a different jar file ("jersey-servlet-1.12.jar").

    I did not find any documentation about this. However having this file in my WEB-INF/lib resolved this issue.

    Hope this helps.

    0 讨论(0)
  • 2020-12-14 08:23

    luigi7up's post above worked for me. I'm using tomcat 7.0.37, maven 3.1.1, and jersey 1.17.1. I did the right click -> properties -> Deployment Assembly -> Click Add -> Java Build Path Entries -> selected Maven Dependencies. I then clicked ok.

    When I first tried this, I noticed that I no longer received the "java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer" error, but I then noticed that I was getting other 'class not found' messages (unfortunately, I didn't document what messages those were). I was using the following jersey dependency:

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.17.1</version>
    </dependency>
    

    I took that out and put in the following dependencies:

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.17.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.17.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.17.1</version>
    </dependency>
    

    Things began to work after that.

    Hope this helps someone!

    0 讨论(0)
  • 2020-12-14 08:25

    Solution:

    Only add the dependency in pom.xml:

     <dependency>
          <groupId>com.sun.jersey</groupId>
          <artifactId>jersey-servlet</artifactId>
          <version>1.13</version>
     </dependency>
    

    Now your application will have the class com.sun.jersey.spi.container.servlet.ServletContainer

    ps: Remember to check if the libraries are being sent to the tomcat deploy.

    To check:

    Right-click on your project -> Properties -> Deployment Assembler and make sure the Source tab contains Maven Dependecies.

    Otherwise:

    Click on button Add -> Java Build Path -> Maven Dependecies -> Finish.

    Ready whenever you run the application all the libs will be imported in the deploy.

    ps: Where the Maven project is updated, you must remake these steps.

    0 讨论(0)
  • 2020-12-14 08:26

    If you're working with Maven then the possible issue might be that your jars don't get deployed to your Tomcat. So, you have your Maven Dependencies in the Java Build Path (Project > Properties > Build path), but when running the project on your Tomcat from Eclipse Maven Dependencies don't get deployed to TOmcat. To solve this you have to: right click > properties and select "Deployment Assembly". And add Java Build Path Entries. This way you're telling the WTP plugin (the one running Tomcat within Eclipse) that it should also copy the Maven's jars enter image description here

    0 讨论(0)
  • 2020-12-14 08:26

    I added it to the WEB-INF/lib directory but it did not work until I refreshed the lib folder from Eclipse and then it started working.

    0 讨论(0)
  • 2020-12-14 08:30

    Anjaneya Reddy, as you've pointed out, the class isn't even in the JAR it's supposed to be in. What baffles me, where is it and where in the documentation does it touch on this?!?

    With everything being so Maven friendly now, it's difficult to bang out a simple tutorial without needing to depend on it.

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