且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JSF托管bean在jar中没有实例化

更新时间:2023-10-06 10:18:52

看起来像Base项目 - 没有正确导出会话bean的项目。 JSF要求将 faces-config.xml 直接放在 META-中的 sbeans.jar 中INF 目录。但是,根据您的描述,Base项目是一个Web项目。当我创建这样的项目并使用你的方式导出它时,我得到了以下结构:

Looks like Base project - the one with session bean is not correctly exported. JSF requires faces-config.xml to be placed in sbeans.jar directly in META-INF directory. However, according to your description Base project is a web project. When I created such project and exported it using the way you did I got the following structure:

sbeans.jar
  |--META-INF (empty)
  |--WebContent
       |--META-INF
            |--faces-config.xml

如您所见 faces-config.xml 放在错误的位置。

As you see faces-config.xml is placed in wrong place.

要解决此问题:


  • 将项目类型更改为普通java - 无论如何将其导出为JAR不是WAR,不是吗? (看起来唯一的方法是从头开始创建新项目)。然后,您可以使用以下提示 https://***.com/a/11027541/1071508 生成所有WAR只需点击几下鼠标即可实现依赖。

  • 如果无法更改项目类型,请考虑将项目转换为maven,以便利用插件。然后,您可以在创建期间重命名WAR:重命名WAR中的Maven依赖关系WEB-INF / lib文件夹

  • 如果由于某种原因无法使用先前的解决方案


    • create META-INF Java Resources / src 中并放置 faces-config.xml 那里

    • 或将项目导出为WAR,并在导出后将其重命名为 .jar

    • change project type to plain java - you anyway export it as JAR not WAR, don't you? (looks like the only way to do it is to create new project from scratch). Then you can then use the following hint https://***.com/a/11027541/1071508 to generate WAR with all dependencies with only few mouse clicks.
    • if changing project type is not possible consider converting projects to maven so that you take advantage of plugins. Then you can rename the WAR during creation: Renaming Maven dependency in WAR's WEB-INF/lib folder
    • if previous solution is not possible for some reason
      • create META-INF in Java Resources/src and place faces-config.xml there
      • or export project as WAR and rename it to .jar after exporting