Maven - JSF 2.0不适用于嵌入式tomcat [英] Maven - JSF 2.0 doesn't work on embedded tomcat

查看:179
本文介绍了Maven - JSF 2.0不适用于嵌入式tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JSF 2.2,Primefaces,Tomcat 7依赖项创建了一个Maven Web应用程序。

I created a Maven Web Application using JSF 2.2 , Primefaces, Tomcat 7 dependencies.

我的JSF的实现是Mojarra 2.2.4,我在POM上添加了这个依赖项:

My JSF's implemention is Mojarra 2.2.4, I added this dependecies on my POM:

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.4</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.4</version>
        <scope>compile</scope>
    </dependency>

但不幸的是,我遇到了 tomcat7-maven-plugin 及其嵌入式tomcat。如果我使用 tomcat7:run 命令,我的webapp启动没有问题,但是当它尝试加载托管bean时,我收到此错误:

But unfortunately, I have problem with tomcat7-maven-plugin and its embedded tomcat. If I use tomcat7:run command, my webapp starts without problem, but when it try to load managed bean I receive this error:


目标无法到达,标识符'testBean'已解析为空

Target Unreachable, identifier 'testBean' resolved to null

这是一个标志webapp使用 JSF 1.x 而不是 JSF 2.x JSF 1.x 的配置程序无法识别 @ManagedBean 注释,这将导致它们未被加载/初始化自动完成而不需要faces-config.xml。

This is a sign that the webapp is using JSF 1.x instead of JSF 2.x. The configurator of JSF 1.x does not recognize @ManagedBean annotations which will cause that they're not loaded/initialized automagically without the need for faces-config.xml.

我正在使用tomcat embedded 7.0.50,使用它进行配置: http://tomcat.apache.org/maven-plugin-trunk/tomcat7 -maven-plugin / adjust-embedded-tomcat-version.html

I'm using tomcat embedded 7.0.50, configured using it: http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/adjust-embedded-tomcat-version.html

尽管我不认识 @ManagedBean 注释,它只能在 faces-config.xml 上使用managedbean标签。

But despite I doesn't recognize @ManagedBean annotaions, it works only using managedbean tag on faces-config.xml.

有没有一种方法,包括 JSF 2.x 支持Tomcat Embedded for maven7-tomcat-plugin

Is there a way to include JSF 2.x support to Tomcat Embedded for maven7-tomcat-plugin?

PS: tomcat7:run-war 有效,但我不喜欢因为它显然是静态运行,没有任何改变的可能性xhtml代码(例如)在飞行中。

PS: tomcat7:run-war works, but I don't like because obviously it a static run, without any possibility to change xhtml code (e.g.) on fly.

解决方案

我解决了从以下步骤切换到Mojarra 2.2.4到MyFaces 2.2.0:

I resolved switched from Mojarra 2.2.4 to MyFaces 2.2.0 following these steps:


  1. 删除我的POM中的Mojarra dependecies

  2. 在我的POM中添加MyFaces dependecies:

  1. remove Mojarra dependecies in my POM
  2. add MyFaces dependecies in my POM:

<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-api</artifactId>
    <version>2.2.0</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-impl</artifactId>
    <version>2.2.0</version>
    <scope>compile</scope>
</dependency>


  • 在我的web.xml上更改listener-class

  • change listener-class on my web.xml

    <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    

    添加上下文 - 我的web.xml上的参数

    add context-param on my web.xml

    <context-param>
         <description>Defines which packages to scan for beans, separated by commas.
             Useful for when using maven and jetty:run (version 6) or tomcat:run
        </description>
        <param-name>org.apache.myfaces.annotation.SCAN_PACKAGES</param-name>
        <param-value>eu.dedalus</param-value>
    

    .5从WEB-INF / lib中删除jsf-api e jsf-impl。

    .5 remove jsf-api e jsf-impl from WEB-INF/lib.

    .6 [仅限ECLIPSE] 使用M2REPO变量在Build Path中添加myfaces.api和myfaces-impl库并删除jsf-api和jsf-impl库。

    .6 [ECLIPSE ONLY] add myfaces.api and myfaces-impl libraries in Build Path using M2REPO variable and remove jsf-api and jsf-impl libraries.

    感谢 https://stackoverflow.com/users/814956/lu4242

    这篇关于Maven - JSF 2.0不适用于嵌入式tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆