异常处理_Maven之web项目java.lang.LinkageError

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常处理_Maven之web项目java.lang.LinkageError相关的知识,希望对你有一定的参考价值。

浏览器运行项目异常如下:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type p.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory; used in the signature
	org.apache.jsp.index_jsp._jspInit(index_jsp.java:31)
	org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
	org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:181)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.22 logs.

刚看到该异常有点蒙,Ljavax/el/ExpressionFactory什么鬼,我的servlet-api.jar和jsp-api.jar都有啊

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>servlet-api</artifactId>
  <version>6.0.37</version>
</dependency>
<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.1</version>
</dependency>  

通过网上的解释是tomcat1.7中的servlet-api.jar包,jsp-api.jar等与自己lib中的jar有所冲突

给的解决方案就是去掉自己项目中lib中冲突的jar包

但是问题又来了,那自己的是maven项目重启不就找不到相关jar包了吗,启动不就报错了吗

好吧,那我就设置包的作用范围为provided

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

重新发布,启动tomcat,运行,成功,谢谢老天

PS_Maven_scope:

在POM 4中,<dependency>中<scope>,它主要管理依赖的部署,目前<scope>可以使用5个值
  * compile: 缺省值,适用于所有阶段,会随着项目一起发布
  * provided: 类似compile,期望JDK、容器或使用者会提供这个依赖,如servlet.jar
  * runtime: 只在运行时使用,如JDBC驱动,适用运行和测试阶段
  * test: 只在测试时使用,用于编译和运行测试代码,不会随项目发布
  * system: 类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它

以上是关于异常处理_Maven之web项目java.lang.LinkageError的主要内容,如果未能解决你的问题,请参考以下文章

Maven之java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTags异常分析

IntelliJ IDEA的Maven项目在修改时报java.lang.OutOfMemoryError: PermGen space异常

java.lang.StackOverflowError 异常处理

eclipse运行maven项目报错java.lang.ClassNotFoundException: xxxxxx

maven+SpringMVC框架开发启动tomcat报监听异常

Java之运行时异常与编译时异常区别