Question

I tried to deploy an Spring application on tomcat7 through tomcat7-maven-plugin (tomcat7:deploy), but when to execute the application, I get this error :

INFO: validateJarFile(C:\Program Files (x86)\apache-tomcat-7.0.47\webapps\MyApp\WEB-
INF\lib\servlet-api-2.5-6.1.11.jar) - jar not loaded. See Servlet Spe c 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class 16-gen-2014 14.18.25 org.apache.catalina.core.StandardContext startInternal GRAVE: Error listenerStart 16-gen-2014 14.18.25 org.apache.catalina.core.StandardContext startInternal GRAVE: Context [/MyApp] startup failed due to previous errors

while if I use jetty through jetty:run everything works.

This is my plugins configuration

        <!-- To launch embded jetty server -->
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>
            <configuration>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                </webAppConfig>
            </configuration>
        </plugin>
    <!-- To launch embded tomcat server -->
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <url>http://localhost:8081/manager/text</url>
                <server>my-tomcat</server>
                <path>/MyApp</path>
            </configuration>
        </plugin>

while these are my dependencies:

    <!-- Spring dependencies -->
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
         <exclusions>
        <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

 <!-- default j2ee dependencies  -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>${servlet-api.version}</version>
        <scope>provided</scope>
    </dependency>

How can I solve it?

Was it helpful?

Solution

the important part of the error message is

INFO: validateJarFile(C:\Program Files (x86)\apache-tomcat-7.0.47\webapps\MyApp\WEB- INF\lib\servlet-api-2.5-6.1.11.jar) - jar not loaded. See Servlet Spe c 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

This means that you're trying to load servlet-api-2.5-6.1.11.jar as part of a web application which contains the definition of javax.servlet.Servlet. Section 9.7.2 of the mentioned specification states that the classloader which the container uses to load servlets must not allow the WAR to override J2SE or Java servlet API classes.


In my case I managed to exclude certain jars when building the war file with the following lines in the pom.xml file:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.1-alpha-2</version>
  <configuration>
  ...
    <packagingExcludes>WEB-INF/lib/javax.servlet-*.jar</packagingExcludes>
  ...
  </configuration>
</plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top