0

I'm following directions from book "Introducing Maven, Apress", to create a simple web app: HelloWorld!! in a JSP . With Maven and Tomcat7 and using following artifact: (by the way I'm using win7)

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp

The structure created is as follow:

gswm-web
|_pom.xml
|_src
    |_main
          |_resources
          |_webapp
                  |_WEB-INF
                  |        |_web.xml
                  |_index.jsp

And pom.xml looks as below, with a tomcat plug-in added:

<project xmlns="http://maven.apache.org/POM/4.0.0"      
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0    
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.apress.gswmbook</groupId>
<artifactId>gswm-web</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>gswm-web Maven Webapp</name>
<url>http://maven.apache.org</url>

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>gswm-web</finalName>
 <plugins>
  <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
  </plugin>

</plugins>  

</build>
</project>

then I run from command line in root of project following command:

mvn tomcat7:run

And I'm getting following information:

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------------------------------------------------   
----
[INFO] Building gswm-web Maven Webapp 1.0-SNAPSHOT
[INFO] --------------------------------------------------------------------- 
---
[INFO]
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ gswm-web >>>
Downloading: http://repo.maven.apache.org/maven2/javax/servlet/jsp/jsp-   
api/2.1/jsp-api-2.1.pom
Downloaded: http://repo.maven.apache.org/maven2/javax/servlet/jsp/jsp-   
api/2.1/jsp-api-2.1.pom 
Downloading: http://repo.maven.apache.org/maven2/javax/servlet/jsp/jsp-   
api/2.1/jsp-api-2.1.jar
Downloaded: http://repo.maven.apache.org/maven2/javax/servlet/jsp/jsp-   
api/2.1/jsp-api-2.1.jar 
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ gswm-   
web ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered    
resources, i.e. build is 
platform dependent!
[INFO] skip non existing resourceDirectory 
C:\MauricioFiles\Maven\gswm-book-master\gswm-book-   
master\chapter6\final\gswm-web\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ gswm-web    
---
[INFO] No sources to compile
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ gswm-web <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ gswm-web ---
[INFO] Running war on http://localhost:8080/gswm-web
[INFO] Creating Tomcat server configuration at 
C:\MauricioFiles\Maven\gswm-book-master\gswm-book-   
master\chapter6\final\gswm-web\target\tomcat
[INFO] create webapp with contextPath: /gswm-web
Jun 03, 2015 1:50:08 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 03, 2015 1:50:08 PM org.apache.catalina.core.StandardService    
startInternal
INFO: Starting service Tomcat
Jun 03, 2015 1:50:08 PM org.apache.catalina.core.StandardEngine     
startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Jun 03, 2015 1:50:12 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]

But when I try to display project in browser at port 8080 I'm getting below message:

Jun 03, 2015 1:50:34 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/gswm-web]     
threw exception 
[java.lang.LinkageError: loader constraint violation: loader (instance of   
org/apache/jasper/servlet/JasperLoader) 
previously initiated loading for a different type with name   
"javax/servlet/http/HttpServletRequest"] 
with root cause
java.lang.LinkageError: loader constraint violation: loader 
(instance of org/apache/jasper/servlet/JasperLoader) previously initiated    
loading for a different type with name 
"javax/servlet/http/HttpServletRequest"
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
    at java.lang.Class.getDeclaredMethods(Class.java:1962)
    at      
 org.apache.catalina.util.Introspection.getDeclaredMethods
 (Introspection.java:127)
    at  
 org.apache.catalina.core.DefaultInstanceManager.populateAnnotationsCache
 (DefaultInstanceManager.java:342)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance
(DefaultInstanceManager.java:161)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance
(DefaultInstanceManager.java:149)
    at org.apache.jasper.servlet.JspServletWrapper.getServlet
(JspServletWrapper.java:172)
    at org.apache.jasper.servlet.JspServletWrapper.service
(JspServletWrapper.java:369)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile
(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service
(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service
(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:210)
    at    
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke
(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke
(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run
(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Among other things I have tried, doing some research I have added following lines to pom, without success:

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

Does anybody know how could this be fixed?. Thank you alot

2 Answers 2

1

Do the same for the javax.servlet-api artifact:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>xxxx</version><!-- Whatever version you are using -->
    <scope>provided</scope>
</dependency>

Actually the offending class, HttpServletRequest is in this artifact.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, however the problem persist. I have followed directions and just have changed 'servlet-api' instead of 'javax.servlet-api' the version I'm using is 2.5. Aditionally to this, what other thing do you thing could be causing the trouble?. Thanks
0

The servlet-api dependency in the pom.xml needed the "provided" scope. This is because Tomcat already provides (requires and uses itself) the servlet-api dependency. Maven's dependency scoping rules are defined here

http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>xxxx</version><!-- Whatever version you are using -->
   <scope>provided</scope>
</dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.