Main Tutorials

servlet-api-2.5.jar – jar not loaded

Deployed a “war” file on Tomcat, and hits following error messages :


Jul 17, 2014 7:59:55 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\apache-tomcat-7.0.53\webapps\hc\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. 
See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class

Tools used :

  1. JDK1.7
  2. Maven 3
  3. Tomcat 7

1. Reason

The Tomcat’s container comes with own version of servlet-api.jar, and the “war” file is deploy the same jar again, and causing the Offending class: javax/servlet/Servlet.class.

This is a really common problem for developers who are using Maven as a build tool. Normally, we will include the servlet-api as a project dependency like this :

pom.xml

	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>servlet-api</artifactId>
		<version>2.5</version>
	</dependency>

When building a war file, Maven will include the servlet-api as well.

2. Solution

To fix it, set the scope to provided. This tells Maven use code servlet-api.jar for compiling and testing only, but NOT include it in the WAR file. The deployed container will “provide” the servlet-api.jar at runtime.

pom.xml

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

References

  1. Maven : Introduction to the Dependency Mechanism

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
7 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ash Trick
9 years ago

I have this added into my pom file. While building from the continuous integration server, I don’t want the server to download any JARs. So, I upload the jar to the server manually. So, I have

/maven_repository/javax/servlet/servlet-api/2.5

and the contents are:

servlet-api-2.5.pom.sha1

servlet-api-2.5.pom

servlet-api-2.5.jar.sha1

servlet-api-2.5.jar

_remote.repositories

servlet-api-2.5.pom.lastUpdated

But, still it tries to communicate the server and I still get error while building saying:

Failed to collect dependencies at javax.servle t:servlet-api:jar:2.5: Failed to read artifact descriptor for javax.servlet:servlet-api:jar:2.5: Cou ld not transfer artifact javax.servlet:servlet-api:pom:2.5 from/to central (http://repo.maven.apache .org/maven2): repo.maven.apache.org: Unknown host repo.maven.apache.org

Please help.

Thanks,

ashtrick

Mukesh
9 years ago

I am using maven and I have set the scope as provided

javax.servlet
servlet-api
2.5
provided

Still I am getting this in the log:
INFO: validateJarFile(/spare/local/xxx/apache-tomcat-7.0.53/webapps/MyWebApp/WEB-INF/lib/servlet-api-2.5-6.1.11.jar) – jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class

Vinod Sharma
6 years ago
Reply to  Mukesh

m too getting same problem..any solution have got…plzzz post

ff
9 years ago

in case if someone is not using Maven…do you think what will be soultion???

mkyong
9 years ago
Reply to  ff

Just make sure you do not deployed your own servlet-api.jar. For example, DO NOT include serlvet-api.jar in your war file.

Java_User
9 years ago
Reply to  ff

I am facing the same problem. I am not using the maven still I’m getting this error.
Don’t know what is the solution.

areadaer
7 years ago

problem fixed thanks to you 🙂