Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jar file failed to load in tomcat webapps

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

like image 942
Rajashekhar Rangappa Avatar asked Feb 22 '14 06:02

Rajashekhar Rangappa


People also ask

What is webapps folder in Tomcat?

The webapps directory is where deployed applications reside in Tomcat. The webapps directory is the default deployment location, but this can be configured with the appBase attribute on the <Host> element.

Can jar file be deployed in Tomcat?

Like most servlet containers, Tomcat 4 also supports mechanisms to install library JAR files (or unpacked classes) once, and make them visible to all installed web applications (without having to be included inside the web application itself.

Where is JAR file in Tomcat?

The right place to put a JAR file to make its contents available to a Java web application at runtime is in the WEB-INF\lib directory of the WAR file in which the application is packaged.


2 Answers

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> 
like image 171
Saif Asif Avatar answered Sep 28 '22 07:09

Saif Asif


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'     } 
like image 31
Sanjay Bharwani Avatar answered Sep 28 '22 07:09

Sanjay Bharwani