jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

后端 未结 12 593
有刺的猬
有刺的猬 2020-11-27 03:58

I am running a Maven project which is also a dynamic web project. I have used all Spring libraries in Maven. I created web.xml, but when I start my Tomcat 7 ser

相关标签:
12条回答
  • 2020-11-27 04:37

    You may find the following windows command line useful in tracking down the offending jar file. it creates an index of all the class files in all the jars in the folder. Execute from within the lib folder of your deployed app, then search the index.txt file for the offending class.

    for /r %X in (*.jar) do (echo %X & jar -tf %X) >> index.txt
    
    0 讨论(0)
  • 2020-11-27 04:39

    You get this warning message when the servlet api jar file has already been loaded in the container and you try to load it once again from lib directory.

    The Servlet specs say you are not allowed to have servlet.jar in your webapps lib directory.

    • Get rid of the warning message by simply removing servlet.jar from your lib directory.
    • If you don't find the jar in the lib directory scan for your build path and remove the jar.

    C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\project\WEB-INF\lib
    

    If you are running a maven project, change the javax.servlet-api dependency to scope provided in you pom.xml since the container already provided the servlet jar in itself.

    0 讨论(0)
  • 2020-11-27 04:41

    Remove servlet.jar from source web-inf/lib folder as it is available in tomcat lib folder then it works fine

    0 讨论(0)
  • 2020-11-27 04:46

    The servlet API .jar file must not be embedded inside the webapp since, obviously, the container already has these classes in its classpath: it implements the interfaces contained in this jar.

    The dependency should be in the provided scope, rather than the default compile scope, in your Maven pom:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    
    0 讨论(0)
  • 2020-11-27 04:49

    I've been struggling with this issue and I've tried numerous "solutions".

    However, in the end, the only one that worked and it actually took a few seconds to do it was to: delete and add back new server instance!

    Basically, I right clicked on my Tomcat server in Eclipse under Servers and deleted it. Next, I've added a new Tomcat server. Cleaned and redeployed the application and I got rid of this error.

    0 讨论(0)
  • 2020-11-27 04:49

    Typically when you see this message, it is benign. If it says

    INFO: validateJarFile(/<webapp>/WEB-INF/lib/servlet-api-2.5.jar) - jar not loaded. 
    See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
    

    It means it is ignoring your servlet-api-2.5.jar because tomcat already has a built-in version of that jar, so it isn't going to be using yours. Typically this doesn't cause an issue.

    If however it says WEB-INF/lib/my_jar.jar - jar not loaded...Offending class: javax/servlet/Servlet.class

    then what you can do (in my instance, it's a shaded jar) is run

    $ mvn dependency:tree

    and discover that you have a transitive dependency on "something" that depends on a jar that is either servlet-api or something like it (ex: tomcat-servlet-api-9.0.0). So add an exclusion to that to your pom, ex: (in my case, tomcat, in your case, probably the ones mentioned in the other answers):

     <dependency>
        ...
        <exclusions>
          <exclusion>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-servlet</artifactId>
          </exclusion>
        </exclusions> 
    </dependency>
    
    0 讨论(0)
提交回复
热议问题