Tomcat 7 LinkageError:违反加载器约束

发布于 2024-12-05 15:12:09 字数 6320 浏览 0 评论 0原文

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>

这个线程加载器约束违规描述了tomcat 6中的相同问题,但这无助于解决我的问题。

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

I am trying to run mkyong hello world JSF2 example http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/

POM.xml is

<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>

This thread loader constraint violation describes same issue in tomcat 6 but it is not help to solve my issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

黒涩兲箜 2024-12-12 15:12:09

我不做 Maven,但考虑到 Pascal Thivent 在您链接的问题中的答案,似乎只要目标运行时已经开箱即用,您就需要将 Maven 依赖项标记为 provided

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

此外,在解决问题中所述的问题后,您将遇到第二个主要问题 Mojarra 2.1.0 在 Tomcat 中无法工作。升级到 Mojarra 2.1.1 或更高版本(当前为 2.1.3)。另请参阅 Mojarra 下载页面 了解 pom 片段。

I don't do Maven, but given the answer of Pascal Thivent in your linked question, it seems that you need to mark a Maven dependency as provided whenever the target runtime already ships with it out the box.

Tomcat as being a simple servletcontainer ships with JSP, Servlet and EL out the box (only not with JSF and JSTL). The exception message which you got indicates duplication of the JSP API in the classpath. I suggest to set the JSP and Servlet entries in your pom.xml to provided as well.

Further, you will get a second major problem after you fix the problem as stated in the question, Mojarra 2.1.0 does not work in Tomcat. Upgrade to Mojarra 2.1.1 or newer (it's currently at 2.1.3). See also the Mojarra download page for pom snippets.

淡莣 2024-12-12 15:12:09

评论

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

对我来说很有用。似乎因为 jsp 已经提供,所以添加依赖项是不必要的并产生错误

commenting out

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

did the trick for me. It seems since jsp was already provided adding the dependency was unnecessary and producing the error

秋千易 2024-12-12 15:12:09

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

使用Tomcat 7作为容器。您必须考虑默认的共享库文件

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

  1. comments-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。

This answer is a supplementation of BalusC's answer. hope this will help.

Use Tomcat 7 as the container. You must consider the default Shared Library Files.

For me, there are such files in directory $TOMCATHOME/lib:

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

That's why you have to mark servlet-api, jsp-api and el-ri as provided, or even exclude the JARs.

去了角落 2024-12-12 15:12:09

尝试将您的 jar 文件放入项目中 BuildPath->Configure BuildPath->Libraries->Add external Jar..

Try to put your jar file in your project BuildPath->Configure BuildPath->Libraries->Add External Jar..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文