【问题标题】:Tomcat 7 LinkageError: loader constraint violationTomcat 7 LinkageError:加载程序约束违规
【发布时间】:2011-11-20 23:34:33
【问题描述】:
INFO: Deploying web application archive test-1.0-SNAPSHOT.war
20-Sep-2011 12:08:42 org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\software\apache-tomcat-7.0.21\webapps\test-1.0-SNAPSHOT\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
20-Sep-2011 12:08:42 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.1.0 (SNAPSHOT 20100817) for context '/test-1.0-SNAPSHOT'
20-Sep-2011 12:08:42 com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
20-Sep-2011 12:08:43 com.sun.faces.config.ConfigureListener contextInitialized
SEVERE: Critical error during deployment: 
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/catalina/loader/WebappClassLoader) of the current class, com/sun/faces/config/ConfigureListener, 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 com.sun.faces.config.ConfigureListener.registerELResolverAndListenerWithJsp(ConfigureListener.java:684)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:240)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
20-Sep-2011 12:08:43 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.RuntimeException: 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/catalina/loader/WebappClassLoader) of the current class, com/sun/faces/config/ConfigureListener, 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 com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:290)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
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/catalina/loader/WebappClassLoader) of the current class, com/sun/faces/config/ConfigureListener, 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 com.sun.faces.config.ConfigureListener.registerELResolverAndListenerWithJsp(ConfigureListener.java:684)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:240)
    ... 8 more
20-Sep-2011 12:08:43 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
20-Sep-2011 12:08:43 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/test-1.0-SNAPSHOT] startup failed due to previous errors

我正在尝试运行 mkyong hello world JSF2 示例http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/

POM.xml 是

<dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.0-b03</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.0-b03</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

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

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
    </dependency>

    <dependency>
        <groupId>com.sun.el</groupId>
        <artifactId>el-ri</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>

这个线程loader constraint violation 描述了tomcat 6 中的相同问题,但它无助于解决我的问题。

【问题讨论】:

  • 我将分享 Fred Bricon 的这个答案,它解决了我遇到的同样问题:stackoverflow.com/a/10101843/1712925(简而言之,可能应该安装 m2e-wtp 插件,否则范围提供的配置将无法使用WTP Tomcat)

标签: jsf tomcat maven jsf-2


【解决方案1】:

我不使用 Maven,但鉴于 Pascal Thivent 在您的链接问题中的回答,您似乎需要将 Maven 依赖项标记为 provided,只要目标运行时已经附带了它。

Tomcat 作为一个简单的 servlet 容器,随 JSP、Servlet 和 EL 开箱即用(只有 JSF 和 JSTL 没有)。您收到的异常消息表明类路径中的 JSP API 重复。我建议您也将pom.xml 中的JSP 和Servlet 条目设置为provided

此外,在您解决了问题Mojarra 2.1.0 does not work in Tomcat 中所述的问题后,您将遇到第二个主要问题。升级到 Mojarra 2.1.1 或更新版本(目前为 2.1.3)。另请参阅Mojarra download page for pom sn-ps。

【讨论】:

  • 我已将 servlet-api、jsp-api 和 el-ri 作为提供的。即提供。但是没有使用同样的错误发生。
  • 那么说明你在部署的webapp的/WEB-INF/lib文件夹中还有JAR。仔细检查和清理。
  • 假设我在另一个没有提供这些 jars 的应用程序服务器中部署,那么这将是一个问题,不是吗?这种情况如何解决?
  • 每个 JSP/Servlet 容器都已经附带了 JSP/Servlet/EL 库(您认为它们还能如何运行 JSP/Servlet webapps?)。只有 JSF 和 JSTL(以及许多其他)已经由更成熟的应用服务器提供,例如 Glassfish、JBoss AS 等(Tomcat 基本上是准系统 servletcontainer)。如果您需要部署到真正的应用服务器,则需要更改您的 pom 以将 JSF/JSTL 标记为已提供。
  • 好的,但是当我尝试在带有 WTP 的 Eclipse-indigo 中运行 Tomcat 7 时,这个位置仍然存在 servlet-api、jsp-api 和 el-ri.jar 文件(元数据\.plugins\ org.eclipse.wst.server.core\tmp0\wtpwebapps\test\WEB-INF\lib) 导致服务器加载错误。
【解决方案2】:

注释掉

<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
</dependency> 

为我做了诀窍。似乎因为已经提供了jsp,所以添加依赖项是不必要的并产生错误

【讨论】:

    【解决方案3】:

    此答案是对 BalusC 答案的补充。希望这会有所帮助。

    使用 Tomcat 7 作为容器。您必须考虑默认的Shared Library Files

    对我来说,目录$TOMCATHOME/lib中有这样的文件:

    1. annotations-api.jar
    2. catalina-ant.jar
    3. catalina-ha.jar
    4. ...
    5. jsp-api.jar
    6. servlet-api.jar
    7. ...

    这就是为什么您必须将 servlet-api、jsp-api 和 el-ri 标记为 provided,甚至排除 JAR。

    【讨论】:

      【解决方案4】:

      尝试把你的jar文件放到你的项目BuildPath->Configure BuildPath->Libraries->Add External Jar..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-04
        • 1970-01-01
        • 2018-01-14
        • 2013-08-18
        相关资源
        最近更新 更多