Java 加载器约束违规
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3761249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
loader constraint violation
提问by
I encountered the problem of having the same .jar (for my case, el-api.jar v2.1)twice for one project, hence, the following error stack when I try to run my project using Tomcat 6.
我遇到了一个项目两次使用相同 .jar(就我而言,el-api.jar v2.1)的问题,因此,当我尝试使用 Tomcat 6 运行我的项目时,出现以下错误堆栈。
WARNING: Unexpected error forwarding to login page
javax.servlet.ServletException: 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/login_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 javax/el/ExpressionFactory used in the signature
at java.lang.Thread.run(Thread.java:619)
Caused by: 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/login_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 javax/el/ExpressionFactory used in the signature
I have found the http://blog.springsource.com/2008/10/20/understanding-the-osgi-uses-directive/
我找到了 http://blog.springsource.com/2008/10/20/understanding-the-osgi-uses-directive/
but that is not useful as the solution effects too many parts of my project.
但这没有用,因为该解决方案影响了我项目的太多部分。
I can't make any changes to the Tomcat as well as the project will be used by many other user.
我无法对 Tomcat 进行任何更改,并且该项目将被许多其他用户使用。
The current work around is to manuelly delete the el-api.jar every time we do a build AND uses Tomcat6. Then we need to put the .jar back as that is requested for other stuff.
当前的解决方法是每次我们进行构建并使用 Tomcat6 时手动删除 el-api.jar。然后我们需要把 .jar 放回去,因为这是其他东西的要求。
I am used Maven 2 and Maven 3 to build. (btw, did anyone know about use Maven3 on Jruby?)
我使用 Maven 2 和 Maven 3 来构建。(顺便说一句,有人知道在 Jruby 上使用 Maven3 吗?)
Can anyone help me with the issue?
任何人都可以帮我解决这个问题吗?
采纳答案by Pascal Thivent
I encountered the problem of having the same .jar (for my case, el-api.jar v2.1)twice for one project, hence, the following error stack when I try to run my project using Tomcat 6.
我遇到了一个项目两次使用相同 .jar(就我而言,el-api.jar v2.1)的问题,因此,当我尝试使用 Tomcat 6 运行我的项目时,出现以下错误堆栈。
Then mark the el-api.jar artifact as provided
, if it is.
然后将 el-api.jar 工件标记为provided
,如果是的话。
The current work around is to manuelly delete the el-api.jar every time we do a build AND uses Tomcat6. Then we need to put the .jar back as that is requested for other stuff.
当前的解决方法是每次我们进行构建并使用 Tomcat6 时手动删除 el-api.jar。然后我们需要把 .jar 放回去,因为这是其他东西的要求。
A much better way to handle this would be to declare the dependency inside profiles and to mark it as provided
(e.g. in a "tomcat6" profile) or not depending on the needs.
处理此问题的更好方法是在配置文件中声明依赖项并将其标记为provided
(例如在“tomcat6”配置文件中)或不取决于需要。
回答by Jim Sime
I got this error attempting to run the Spring (3.0.5) sample mvc-ajax with Tomcat 7.
尝试使用 Tomcat 7 运行 Spring (3.0.5) 示例 mvc-ajax 时遇到此错误。
Tomcat 7 uses el-api 2.2 and jsp-api 2.2. The mvc-ajax pom file specifies jsp-api 2.1, which also contains the classes in el-api.
Tomcat 7 使用 el-api 2.2 和 jsp-api 2.2。mvc-ajax pom 文件指定了 jsp-api 2.1,其中也包含了 el-api 中的类。
To get this running I commented out jsp-api 2.1 from the pom. This allowed Tomcat to use its own (more recent) version.
为了让它运行,我从 pom.xml 注释掉了 jsp-api 2.1。这允许 Tomcat 使用它自己的(更新的)版本。