简体   繁体   English

在Jboss 5.0上启动JSF应用程序时出错

[英]Error starting JSF application on Jboss 5.0

I'm new to JSF, I've recently started working with a tutorial. 我是JSF的新手,最近开始学习教程。 I've created application exactly as the information provided in the tutorial. 我已经完全按照教程中提供的信息创建了应用程序。 However when I start the server, I'm getting following error: 但是,当我启动服务器时,出现以下错误:

Exception sending context initialized event to listener instance of class org.jboss.web.jsf.integration.config.JBossJSFConfigureListener
java.lang.ClassCastException: com.sun.faces.config.WebConfiguration cannot be cast to com.sun.faces.config.WebConfiguration
    at com.sun.faces.config.WebConfiguration.getInstance(WebConfiguration.java:154)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:145)

web.xml web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>Hello, World</display-name>
    <description>Welcome to JavaServerFaces</description>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>

</web-app>

As indicated in tutorial I've added jsf-api and jsf-impl in Web-Inf/lib, however googling for the same I found that jboss has its own jsf version which might be polluting my application with multiple jsf versions. 如本教程中所述,我在Web-Inf / lib中添加了jsf-api和jsf-impl,但是通过同样的搜索,我发现jboss有自己的jsf版本,可能会用多个jsf版本污染我的应用程序。 If that's the case then how do I resolve the issue or if I'm wrong then what is the reason behind the error ? 如果是这样,那么我该如何解决该问题,或者如果我错了,那么错误背后的原因是什么?

Just to add, as I believe its the jar files conflit I've tried to add the jar files imported with jboss from jboss-5.1.0.GA\\server\\default\\deploy\\jbossweb.sar\\jsf-libs , still all in vain. 只是要添加,因为我相信它的jar文件已经限制,所以我尝试添加从jboss-5.1.0.GA\\server\\default\\deploy\\jbossweb.sar\\jsf-libs用jboss导入的jar文件徒劳的。

Please help. 请帮忙。

A better way to cope up with the conflict is to add a context parameter in web.xml as I've mentioned below: 解决冲突的更好方法是在web.xml中添加上下文参数,如下所述:

<context-param>
      <param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
      <param-value>true</param-value>
</context-param>

Check out: Bundling JSF Inside Your WAR 检出: 将JSF捆绑在WAR中

I don't know how your Eclipse is configured(Java EE/JBoss tools and so on). 我不知道您的Eclipse是如何配置的(Java EE / JBoss工具等)。 But you should add a server runtime to your webproject: 但是您应该将服务器运行时添加到您的Web项目中:

  1. Add server runtime 添加服务器运行时

1.1 open Server view in Eclipse 1.1在Eclipse中打开服务器视图

1.2 Context menu and then -> new Server->select JBoss 5.0 server type 1.2上下文菜单,然后->新服务器->选择JBoss 5.0 服务器类型

1.3 Server runtime enviroment-> add 1.3服务器运行时环境->添加

1.4 Home directory-> your sever home/default for example 1.4主目录->例如,您的服务器主目录/默认目录

  1. Now change the buildpath of your webproject. 现在更改您的Web项目的构建路径。

2.1. 2.1。 Add library->server runtime->select your new runtime 添加库->服务器运行时->选择新的运行时

2.3 No JSF or other libs in your ear or in your webprojects Web-Inf/lib 2.3在您的耳朵或Web项目中没有JSF或其他库Web-Inf / lib

Now you have all the Jboss-libs including the jsf-libs in your classpath - controlled by Eclipse - and you don't have to worry about setting jars from server lib and so on. 现在,您已在类路径中拥有了所有Jboss-libs,包括jsf-libs(由Eclipse控制),而您不必担心从服务器lib设置jar等等。

I hope it helps. 希望对您有所帮助。 In a similar way I just create a test-project 以类似的方式,我只是创建一个测试项目

Yep looks like a jar version collision 是的,看起来像罐子碰撞

Remove JSF dependencies from Application: If you are building the project using maven, you can set the dependencies scope to provided . 从应用程序中删除JSF依赖项:如果要使用maven构建项目,则可以将依赖项范围设置provider

Remove dependencies scope from JSF (if you want to use your own jars.) Consider using Jboss application description and exclude the JSF dependecies. 从JSF中删除依赖关系范围(如果要使用自己的jar。)请考虑使用Jboss应用程序描述,并排除JSF依赖关系。

I am not aware of JBoss 5 XML format, so posting for JBoss 7 我不知道JBoss 5 XML格式,因此发布JBoss 7

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="com.sun.jsf-impl" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

Should be something similar to this. 应该与此类似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM