Setting up Servlet / JSP jars in pom.xml for Tomcat 7
eclipse, maven, servlets, tomcat
Solution
It is the responsibility of the web application container to provide both the Servlet/JSP API and implementation files. With your current Maven setup you are causing these library files to be bundled in your app, which consequently causes the class loader problems you are seeing in your log.
When trying to import packages such as javax.servlet.*; Eclipse complained that it does not have it inside its classpath (build path).
Yes, you need the API libraries in your classpath in order to compile code that depends on them. You want to include these libraries on your build classpath, while at the same time not including them in the final deployable. You do this with Maven by identifying the `scope` of the dependent libraries as `provided`. Which basically means "these libraries are needed for compilation, but will eventually be provided by the app container, so don't actually include them in the deployable".
Also, I can't seem to find the right versions for servlet-api 3.0 or jsp 2.2 in the maven repository
The Servlet 3.0 and JSP 2.2 API's have been bundled in the common JavaEE Web API. This is the dependency that you need to specify in your POM. Illustrated:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Problem
I am using JDK 1.6, Maven 2.2.1, Tomcat 7 and Eclipse Juno (Enterprise Edition). When trying to import packages such as javax.servlet.*; Eclipse complained that it does not have it inside its classpath (build path). So, what I did was include the following dependencies in my pom.xml file: ``` <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency> ``` During tomcat server startup: ``` INFO: Deploying web application archive C:\DevTools\tomcat\apache-tomcat-7.0.32\webapps\myapp.war Dec 20, 2012 4:55:41 PM org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(C:\DevTools\tomcat\apache-tomcat-7.0.32\webapps\myapp\WEB-INF\lib\servlet-api-2.3.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class ``` Why is it logging this message? Also, I can't seem to find the right versions for servlet-api 3.0 or jsp 2.2 in the maven repository http://mvnrepository.com/ Kindly help me...