26

This is what the error i got when i try to deploy maven project to tomcat

mvn tomcat7:deploy

Error :

INFO: validateJarFile(D:\Softwares\tomcat\apache-tomcat-7.0.50\webapps\myWebApp_
1\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.
0, section 10.7.2. Offending class: javax/servlet/Servlet.class

But the javax.servlet-api-3.0.1.jar is there in WEB-INF\lib Thanks

Saif Asif
  • 5,075
  • 2
  • 27
  • 46
  • possible duplicate of [Error: Servlet Jar not Loaded... Offending class: javax/servlet/Servlet.class](http://stackoverflow.com/questions/1993493/error-servlet-jar-not-loaded-offending-class-javax-servlet-servlet-class) – Raedwald Feb 13 '15 at 13:07

4 Answers4

46

INFO: validateJarFile(D:\Softwares\tomcat\apache-tomcat-7.0.50\webapps\myWebApp_ 1\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded

Servlet3.0 is already shipped with the tomcat inside its lib folder and by default tomcat will always load the servlet jar present there. Thats why you are getting the warning that tomcat is not loading your jar inside the project.

Simple solution : If you are using maven, set its scope as provided inside the pom.xml and maven will not place it in the WEB-INF/lib of your project. Something like

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>3.0</version>
    <scope>provided</scope>
</dependency>
Saif Asif
  • 5,075
  • 2
  • 27
  • 46
  • 1
    What if I am not using maven (Eclipse + terminal launched Tomcat) ? – Patryk May 24 '14 at 18:29
  • If you aren't using maven, then you must have packaged the `servlet-api` jar inside the WEB-INF/lib folder of the war. Check the lib folder to verify and remove it if it is present there. – Saif Asif May 24 '14 at 18:32
  • That helped, thanks but I have found out that while importing my project from SVN I can see that Apache CXF being in the dependencies of my project has a `geronimo-servlet_3.0_spec-1.0.jar` dependency and it is being packaged to the `lib/` directory of my `.war`. Any ideas how to remove it from there ? – Patryk May 24 '14 at 18:42
  • I can't properly recall if I was getting this warning when I was working on cxf but are you getting the `jar not loaded` warning for this particular 'geronimo-servlet_3.0_spec-1.0.jar' as well in the tomcat logs? If yes, you always have the option to unpack the cxf jar and remove the servlet_spec jar from it and then re-pack it. – Saif Asif May 24 '14 at 18:50
  • cxf jar does not contain any servlet jar. There is `geronimo-servlet_3.0_spec-1.0.jar` but in the dir next to cxf .jar. If I remove it then I cannot create `.war` from my app. – Patryk May 24 '14 at 20:21
  • I see.. can you post a new question for this so that it can be investigated independantly. – Saif Asif May 24 '14 at 20:28
  • 1
    Done! https://stackoverflow.com/questions/23849471/apache-cxf-geronimo-servlet-3-0-spec-1-0-jar-jar-not-loaded-having-tomcats-se – Patryk May 24 '14 at 20:44
  • after search a lot I got answer and very helpful for me. – sumit sharma Jun 09 '15 at 07:06
  • You need to add `3.0.1` see [this](https://stackoverflow.com/questions/24855531/how-to-config-maven-to-use-servlet-3) post. – Ahmed Akhtar Aug 01 '17 at 05:45
2

Precise explanation by Saif asif.

I was using gradle as the build tool. It worked for me to exclude the tomcat-servlet-api.jar which is by default provided by tomcat.

You need to know which of your dependency is transitively adding tomcat-servlet-api.jar to the war and then exclude it using following

 compile ('your dependency goes here') {
        exclude module:'tomcat-servlet-api'
    }
Sanjay Bharwani
  • 1,687
  • 21
  • 22
1

This is just an warning that appears in your log, not an error. Your project will still deploy if you ignore this.

You can get get rid of this error by rebuilding your .war using maven and copying it into \webapps\ removing your old files.

Tim
  • 139
  • 1
  • 5
-2

Best Solution : remove that jar(i.e javax.servlet-api-3.0.1.jar) from lib