1. 程式人生 > >Maven使用Tomcat熱啟動問題:java.lang.LinkageError: loader constraint violation

Maven使用Tomcat熱啟動問題:java.lang.LinkageError: loader constraint violation

F:\JAVA\jdk1.8.0_40\bin\java -Dmaven.multiModuleProjectDirectory=G:\project\GeneralShop -Dmaven.home=E:\apache-maven-3.5.4-bin\apache-maven-3.5.4 -Dclassworlds.conf=E:\apache-maven-3.5.4-bin\apache-maven-3.5.4\bin\m2.conf -javaagent:G:\IntelliJIDEA2017.3\lib\idea_rt.jar=10325:G:\IntelliJIDEA2017.3\bin -Dfile.encoding=UTF-8 -classpath E:\apache-maven-3.5.4-bin\apache-maven-3.5.4\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2017.3 -s E:\apache-maven-3.5.4-bin\apache-maven-3.5.4\conf\settings.xml -Dmaven.repo.local=E:\apache-maven-3.5.4-bin\repository tomcat:run
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.du.general:GeneralShop >---------------------
[INFO] Building GeneralShop Maven Webapp 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) > compile @ GeneralShop >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ GeneralShop ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ GeneralShop ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< tomcat-maven-plugin:1.1:run (default-cli) < compile @ GeneralShop <<<
[INFO] 
[INFO] 
[INFO] --- tomcat-maven-plugin:1.1:run (default-cli) @ GeneralShop ---
[INFO] Running war on http://localhost:8080/GeneralShop
[INFO] Creating Tomcat server configuration at G:\project\GeneralShop\target\tomcat
八月 16, 2018 10:40:03 下午 org.apache.catalina.startup.Embedded start
資訊: Starting tomcat server
八月 16, 2018 10:40:04 下午 org.apache.catalina.core.StandardEngine start
資訊: Starting Servlet Engine: Apache Tomcat/6.0.29
八月 16, 2018 10:40:04 下午 org.apache.coyote.http11.Http11Protocol init
資訊: Initializing Coyote HTTP/1.1 on http-8080
八月 16, 2018 10:40:04 下午 org.apache.coyote.http11.Http11Protocol start
資訊: Starting Coyote HTTP/1.1 on http-8080
八月 16, 2018 10:40:09 下午 org.apache.catalina.core.StandardWrapperValve invoke
嚴重: Servlet.service() for servlet jsp 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"
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.getDeclaredMethods(Class.java:1975)
	at org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:226)
	at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:148)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:745)

前提:使用tomcat7版本

原因分析:

tomcat-servlet-api與容器內部jar包衝突

解決方案:

找到刪除tomcat-servlet-api即可

或者成

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