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
- 坚持
- 网
感谢您的帮助 既然您使用的是您提到的技术堆栈,那么也可以使用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,但没有任何内容说明您必须这样做——您可以根据自己的意愿进行混合和匹配。要点如下:
WEB-INF/lib
类中的任何jar,在运行时将映射到/WEB-INF/classes
beans.xml
启用CDIfaces 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:)