eclipse 具有共享代码的多个 JSF 项目的结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8320486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Structure for multiple JSF projects with shared code
提问by Heizenberg
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.
我有两个共享大量代码的 JSF 项目——java 类、xhtml 文件、标签库、css 和 javascript 文件等。我的开发环境/平台主要由 Eclipse、Ant、Perforce 和 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.
Eclipse 可以很容易地为 java 源添加外部文件夹,但在其他文件类型上存在不足。我很感激任何想法。
回答by BalusC
Create a new "Java Project" in Eclipse. Add it as another project to the Deployment Assemblyproperty 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 Assemblystep will be done automatically.
在 Eclipse 中创建一个新的“Java 项目”。将其作为另一个项目添加到主动态 Web 项目的部署程序集属性。这样,它将自动作为/WEB-INF/lib
Web 项目构建中的JAR 结束。由于较新的 Eclipse 版本,您还可以将项目创建为“Web 片段项目”。这样,部署组装步骤将自动完成。
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.
将所有共享的 JSF2/Facelets 资源文件放在/META-INF/resources
Java 项目的文件夹中。就像对待WebContent/resources
主要的网络项目一样对待它。标签/META-INF/tags
文件可以保存在它们自己的文件夹中。
E.g.
例如
CommonWebProject
|-- META-INF
| |-- resources
| | `-- common
| | |-- css
| | | `-- some.css
| | |-- js
| | | `-- some.js
| | |-- images
| | | `-- some.png
| | |-- components
| | | `-- somecomposite.xhtml
| | `-- sometemplate.xhtml
| |-- tags
| | `-- sometag.xhtml
| |-- beans.xml
| |-- 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" />
...
In case you're using Maven, the /META-INF
folder has to be placed in src/main/resources
and thus NOT src/main/java
.
如果您使用的是 Maven,则/META-INF
必须将文件夹放置在其中src/main/resources
,因此 NOT src/main/java
。
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).
如果要触发JSF2注释扫描仪,以及让你可以把@ManagedBean
,@FacesValidator
,@FacesConverter
和后妃在该项目中,以及创建一个JSF2兼容的/META-INF/faces-config.xml
文件,以及(它甚至可以保持为空)。
<?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.
就这样。