java.lang.LinkageError: loader constraint violation的错误

[b]java.lang.LinkageError: loader constraint violation
是由于容器提供的包和web应用引入的包冲突引起的。
通过maven排除重复引用后解决。具体参见以下指引:[/b]

your application has a JAR file, which is already part the JVM or Servlet Container, in it's WEB-INF/lib folder (or WAR file)
and the version of the JAR files is different to that of the JVM or Servlet Container
JAR files you should never include in your web-app
As a rule, the following jar files should never be part of your webapp:

[list]
[*]j2ee.jar - interfaces are implemented by Tomcat
[*]jasper-*.jar - causes Exceptions, or will do when version of Tomcat is upgraded
[*]jboss.jar - part of jboss - should not be part of your app
[*]jsp-api.jar - causes Exceptions, or will do when version of Tomcat is upgraded
[*]gwt-user.jar - contains javax.servlet.Servlet, so gets ignored by Tomcat
[*]gwt-dev-linux.jar - contains javax.servlet.Servlet, so gets ignored by Tomcat
[*]gwt-dev-windows.jar - contains javax.servlet.Servlet, so gets ignored by Tomcat
[*]rt.jar - not sure why you would, but some have...
[*]servlet-api.jar - this is really old too, switch to compiling with j2ee.jar
[*]servlet.jar - this is really old too, switch to compiling with j2ee.jar
[*]tools.jar - part of VM
[/list]
You may require these for compiling your app (notably servlet-api.jar or j2ee.jar), but they should not be deployed as part of your webapp.

jsp-api.jar and/or jasper-*.jar
Including these files will cause the following exceptions:

javax.servlet.ServletException: loader constraint violation: when resolving method "org.apache.jasper.compiler.JspRuntimeContext...
java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.compiler.JspRuntimeContext...
If these aren't thrown when deploying your app, they most likely will be when the version of Tomcat is next updated. By chance, you might be using exactly the same version as the container. They already exist in the container though, so remove them to save yourself future pain.

servlet-api.jar - the most common mistakenly included JAR
Many developers incorrectly include servlet-api.jar in their WEB-INF/lib folder. This no longer causes an exception because Tomcat and other app servers will recognize it as a problem when deploying the JAR file. However, it does cause the container to ignore any JAR file that contains the javax/servlet/Servlet.class. In this case, you will see the following warning in the system log:
INFO: validateJarFile(/path/app/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java.lang.LinkageErrorloader constraint violation: when resolving method解释为加载器约束错误:在解析方法时。 当Java虚拟机(JVM)在运行时尝试加载类和解析类中的方法时,可能会遇到该错误。这通常发生在以下情况下: 1. 类型冲突:加载器尝试使用两个不同的类加载器加载具有相同名称但不同版本的类,从而导致了方法的冲突。因此,使用了不兼容的类定义。 2. 类重定义:加载器尝试重新定义已经在虚拟机中加载的类,从而导致加载的重复。这可能会导致类的冲突以及方法无法解析。 解决这个问题的方法如下: 1. 检查类加载器:确定是否有多个类加载器同时加载了相同的类。如果是,请确保只有一个类加载器加载相应的类。 2. 更新依赖关系:检查项目的依赖关系,确保所有的依赖项都是最新的版本并且兼容。 3. 清除类缓存:如果问题仍然存在,可以尝试清除JVM的类缓存。可以通过删除临时目录中的所有缓存文件来实现(例如,Java.io.tmpdir系统属性指向的目录)。 4. 更新JVM:确保使用的JVM是最新版本。有时,这种错误可能是由于JVM本身的问题引起的,而在较新的版本中可能已经修复。 总之,加载器约束错误是由于类加载器冲突或类重定义导致的,解决方法包括检查类加载器、更新依赖关系、清除类缓存以及更新JVM版本等。根据具体情况选择适当的解决方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值