Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 在另一个项目的xhtml中使用项目中的bean_Jsf_Maven_Primefaces_Ejb - Fatal编程技术网

Jsf 在另一个项目的xhtml中使用项目中的bean

Jsf 在另一个项目的xhtml中使用项目中的bean,jsf,maven,primefaces,ejb,Jsf,Maven,Primefaces,Ejb,我在同一个应用程序中有几个项目,结构大致如下: --- WAR |--- any *.xhtml files can live here (public) |--- WEB-INF |--- web.xml (optional) |--- persistence.xml (optional) - declare persistence unit used from WEB-INF/classes |--- beans.xml (optional) enable CDI an

我在同一个应用程序中有几个项目,结构大致如下:

--- WAR
 |--- any *.xhtml files can live here (public)
 |--- WEB-INF
   |--- web.xml (optional)
   |--- persistence.xml (optional) - declare persistence unit used from WEB-INF/classes
   |--- beans.xml (optional) enable CDI annotation scanning for WEB-INF/classes
   |--- faces-config.xml (optional) enable JSF annotation scanning in WEB-INF/classes
   |--- *.xhtml files can live here (private - usually templates, ui:composition, etc.)
   |--- classes
     |--- com.example - put managed beans here, EJBs, JPA etities or just about any other *.class
   |---lib
     |--- jpa.jar
       |--- META-INF
         |--- persistence.xml - persistence unit used in this jar
       |--- com.example - JPA entities can live here, gets mapped to WEB-INF/classes at runtime
     |--- ejb.jar
       |--- META-INF
         |--- ejb-jar.xml (optional) but can declare resources here
       |--- com.example - ejbs can live here, gets mapped to /WEB-INF/classes at runtime
     |--- faces.jar
       |--- META-INF
         |--- faces-config.xml - enables scanning JSF specific annotations in this jar
       |--- resources - this gets mapped to the WAR root at runtime, .xhtml can live here
       |--- com.example - put your @ManagedBean s here and @EJB inject anything from ejb.jar, gets mapped to /WEB-INF/classes at runtime
     |--- cdi.jar
       |--- META-INF
         |--- beans.xml - marks this as CDI bean archive
       |--- com.example - CDI beans can live here, gets mapped to WEB-INF/classes at runtime
  • 母公司
    • 耳朵
    • ejb
    • 坚持
我使用Maven来解决所有依赖关系,并将所有内容都很好地捆绑到WAR中,稍后我将其部署到JBoss上

我的问题是,我的大多数模型都在ejb项目中,我需要这些Bean在支持Bean逻辑(在web中)中,或者直接在JSF.xhtml中调用(也在web中)

我浏览了互联网,包括stack overflow,发现了大量关于SPRING和如何导入/导出模块的示例。好吧,因为我没有使用它,我不知道如何继续下去

那么如何从另一个项目导入/使用这些bean呢


感谢您的帮助

既然您使用的是您提到的技术堆栈,那么也可以使用CDI。不管怎样,如果你把所有东西都打包成一场战争,那么在运行时这只是一个模块。假设您具有以下结构:

--- WAR
 |--- any *.xhtml files can live here (public)
 |--- WEB-INF
   |--- web.xml (optional)
   |--- persistence.xml (optional) - declare persistence unit used from WEB-INF/classes
   |--- beans.xml (optional) enable CDI annotation scanning for WEB-INF/classes
   |--- faces-config.xml (optional) enable JSF annotation scanning in WEB-INF/classes
   |--- *.xhtml files can live here (private - usually templates, ui:composition, etc.)
   |--- classes
     |--- com.example - put managed beans here, EJBs, JPA etities or just about any other *.class
   |---lib
     |--- jpa.jar
       |--- META-INF
         |--- persistence.xml - persistence unit used in this jar
       |--- com.example - JPA entities can live here, gets mapped to WEB-INF/classes at runtime
     |--- ejb.jar
       |--- META-INF
         |--- ejb-jar.xml (optional) but can declare resources here
       |--- com.example - ejbs can live here, gets mapped to /WEB-INF/classes at runtime
     |--- faces.jar
       |--- META-INF
         |--- faces-config.xml - enables scanning JSF specific annotations in this jar
       |--- resources - this gets mapped to the WAR root at runtime, .xhtml can live here
       |--- com.example - put your @ManagedBean s here and @EJB inject anything from ejb.jar, gets mapped to /WEB-INF/classes at runtime
     |--- cdi.jar
       |--- META-INF
         |--- beans.xml - marks this as CDI bean archive
       |--- com.example - CDI beans can live here, gets mapped to WEB-INF/classes at runtime
请注意,尽管我在上面的结构中专门分离了jpa.jar、ejb.jar、faces.jar和CDI.jar,但没有任何内容说明您必须这样做——您可以根据自己的意愿进行混合和匹配。要点如下:

  • 对于WAR的
    WEB-INF/lib
    类中的任何jar,在运行时将映射到
    /WEB-INF/classes
  • beans.xml
    启用CDI
  • faces config.xml
    启用JSF注释扫描
  • ejbjar.xml
    在任何地方都不是必需的,但您可以利用它
  • web.xml
    可以存在于
    web-INF/
    中,但不是必需的
  • web fragment.xml
    可以位于
    web-INF/lib
    中任何jar的
    META-INF
    文件夹中,并合并到
    web.xml
  • .xhtml
    JSF文件可以位于
    web-INF/
    (私有)中的web应用程序根目录(public)中,也可以位于
    web-INF/lib
    中任何jar的
    META-INF/resources
    中-所有这些文件都映射到web应用程序根目录(也就是说,如果在jar中,它们在
    META-INF/resource/WEB-INF
    中,那么它们在逻辑上可以在
    WEB-INF/
    中结束)
  • persistence.xml
    可以存在于
    WEB-INF
    中或
    META-INF
    WEB-INF/lib

  • 这应该就涵盖了它-如果有什么不清楚或可以添加的,请告诉我。

    我的Maven不知怎么把它们打包得很奇怪!并不是我所有的bean都以WEB-INF/类结束。它们都在我配置的单独快照中。让我感到不安的是,实现只在WEB-INF/类中搜索…通过bean,你是指JSF吗管理bean或CDI bean还是EJBs?但这并不重要,只是我的所有类都没有映射到Web-INF/C类。这实际上是我的问题。谢谢解释,它帮助我发现了我的打包问题。我已经用Maven修正了它们。不管怎样,我会考虑这个正确答案,就像你提供的IN一样。关于如何打包bean以使其可访问!关于bean,我指的是EJB(@Stateless),其中大多数。基本上,它并没有将我其他jar中的所有bean映射到WEB-INF/classes。另外,我还将研究添加CDI!嗯,从来没有遇到过问题,但是的,CDI ftw:)