java.lang.LinkageError: loader constraint violation
java.lang.LinkageError: loader constraint violation 是由于容器提供的包和web应用引入的包冲突引起的。 通过maven排除重复引用后解决。具体参见以下指引: your application has a JAR file, which is already part the JVM or Servlet Container, in
java.lang.LinkageError: loader constraint violation
是由于容器提供的包和web应用引入的包冲突引起的。
通过maven排除重复引用后解决。具体参见以下指引:
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:
- 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
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
注:web container 和 jvm 已经提供了一些包,而这些包你不需要再提供,否则可能因为版本的问题引起错误 。。
更新:引入servlet依赖,并把其scope设置为provided。。。
如下:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
更多推荐
所有评论(0)