具有共享代码的多个JSF项目的结构 [英] Structure for multiple JSF projects with shared code
问题描述
有没有人找到一种创建和组织共享代码的方法,以便通用代码可以保留在一组文件夹中?
Eclipse可以轻松地为java源添加外部文件夹,但是其他文件类型很少。我会感谢任何想法。
在Eclipse中创建一个新的Java Project。将其作为另一个项目添加到主动态Web项目的部署程序集属性。这样一来,它将自动地作为Web项目构建的 / WEB-INF / lib
中的JAR结束。由于新版本的Eclipse版本,您还可以将该项目创建为Web Fragment Project。这样,部署程序集步骤将自动完成。
将所有这些共享的JSF2 / Facelets资源文件放在 / Java项目的META-INF / resources
文件夹。就像主要的Web项目的 WebContent / resources
一样。标签文件可以保存在自己的 / META-INF / tags
文件夹中。
例如
CommonWebProject
| - META-INF
| | - 资源
| | ` - common
| | | - css
| | | ` - some.css
| | | - js
| | | ` - some.js
| | | - 图像
| | | ` - some.png
| | | - components
| | | ` - somecomposite.xhtml
| | ` - sometemplate.xhtml
| | - 标签
| | ` - sometag.xhtml
| | - faces-config.xml
| | - some.taglib.xml
| | - web-fragment.xml
| ` - MANIFEST.MF
:
与
< h:outputStylesheet library =commonname =css / some.css/>
< h:outputScript library =commonname =js / some.js/>
< h:graphicImage library =commonname =images / some.png/>
< common:somecomposite />
< common:sometag />
< ui:include src =/ common / sometemplate.xhtml/>
...
如果您还要触发JSF2注释扫描器,以便您可以将 @ManagedBean
, @FacesValidator
, @FacesConverter
在该项目中也可以创建一个JSF2兼容的 /META-INF/faces-config.xml
文件(甚至可以保持为空)。
<?xml version =1.0encoding =UTF-8?>
< faces-config
xmlns =http://java.sun.com/xml/ns/javaee
xmlns:xsi =http://www.w3.org / 2001 / XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0 .xsd
version =2.0>
< / faces-config>
全部。
另请参见:
I have two JSF projects that share a lot of code - java classes, xhtml files, tag libraries, css and javascript files etc. My dev environment/platform consists mainly of Eclipse, Ant, Perforce and Tomcat.
Has anyone found a way to create and organize the shared code so that the common code can stay within one set of folders?
Eclipse makes it easy to add external folders for java sources, but falls short on the other file types. I'd appreciate any ideas.
Create a new "Java Project" in Eclipse. Add it as another project to the Deployment Assembly property of the main dynamic web project. This way it will automatically end up as a JAR in /WEB-INF/lib
of the build of the web project. Since newer Eclipse versions, you can also create the project as "Web Fragment Project". This way the Deployment Assembly step will be done automatically.
Put all those shared JSF2/Facelets resource files in /META-INF/resources
folder of the Java project. Just treat it like WebContent/resources
of the main web project. Tagfiles can just be kept in their own /META-INF/tags
folder.
E.g.
CommonWebProject
|-- META-INF
| |-- resources
| | `-- common
| | |-- css
| | | `-- some.css
| | |-- js
| | | `-- some.js
| | |-- images
| | | `-- some.png
| | |-- components
| | | `-- somecomposite.xhtml
| | `-- sometemplate.xhtml
| |-- tags
| | `-- sometag.xhtml
| |-- faces-config.xml
| |-- some.taglib.xml
| |-- web-fragment.xml
| `-- MANIFEST.MF
:
with
<h:outputStylesheet library="common" name="css/some.css" />
<h:outputScript library="common" name="js/some.js" />
<h:graphicImage library="common" name="images/some.png" />
<common:somecomposite />
<common:sometag />
<ui:include src="/common/sometemplate.xhtml" />
...
If you want to trigger the JSF2 annotation scanner as well so that you can put @ManagedBean
, @FacesValidator
, @FacesConverter
and consorts in that project as well, create a JSF2 compatible /META-INF/faces-config.xml
file as well (it can even be kept empty).
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
That's all.
See also:
- Splitting up shared code and web.xml from WAR project to common JAR project
- JSF facelets template packaging
- Obtaining Facelets templates/files from an external filesystem or database
这篇关于具有共享代码的多个JSF项目的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!