公司采用的JSF是primefaces,这个前端MVC框架,个人用的觉得还是蛮不错的,虽然也存在很多不足,但也掩盖不了他的优势,题外话,这货是土耳其的. = =!
刚好身边有个牛人勇哥,就去尝试搭框架自己写写东西,顺便把23个设计模式实际用用啊什么的.
还是非常感谢勇哥啊......说实话我都不知道怎么对勇哥表达敬意了.感觉勇哥和我师父一样了..哈哈.
总体会用到的东西:
1.primefaces版本3.2.
2.jsf morraja
3.Maven3.0.3
总体环境:http://blog.csdn.net/lioncredo/article/details/7385870
3.apache-tomcat-7.0.23
第一步搭建和后台无关
照常建立maven工程
如图操作
接着需要手动建立一个资源文件夹
,右键项目进行project faces操作操作.
可以看到多出了WebContent文件夹.然后把里面的2个文件夹移动位置,再删除此文件夹.
如图所示.现在架子就基本搭建好了.接着就是进行一些配置的修改和jar包的导入.
===========================================================================================================
1.web.xml的配置修改如下:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>CredoBase</display-name> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>faces/login.xhtml</welcome-file> </welcome-file-list> </web-app>
<welcome-file-list>是进入默认项目名不指定URL中使用的页面.
2.faces-config.xml
此时还未未配置.
3.pom.xml配置
如图,是jar包.
POM文件配置信息:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.credo</groupId> <artifactId>CredoBase</artifactId> <version>0.0.1</version> <packaging>war</packaging> <name>CredoBase</name> <properties> <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- repositories配置资源库 --> <repositories> <repository> <id>prime-repo</id> <name>PrimeFaces Maven Repository</name> <url>http://repository.primefaces.org</url> <layout>default</layout> </repository> </repositories> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> <!-- jsf --> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.1.2</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.1.2</version> <type>jar</type> <scope>compile</scope> </dependency> <!-- primefaces --> <dependency> <groupId>org.primefaces</groupId> <artifactId>primefaces</artifactId> <version>3.2</version> <optional>true</optional> </dependency> </dependencies> <build> <!--配置项目war包名--> <finalName>credobase</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <compilerArguments> <endorseddirs>${endorsed.dir}</endorseddirs> </compilerArguments> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.1</version> <executions> <execution> <phase>validate</phase> <goals> <goal>copy</goal> </goals> <configuration> <outputDirectory>${endorsed.dir}</outputDirectory> <silent>true</silent> <artifactItems> <artifactItem> <groupId>javax</groupId> <artifactId>javaee-endorsed-api</artifactId> <version>6.0</version> <type>jar</type> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
四:.settings文件夹下的修改org.eclipse.wst.common.component文件.
因为是maven项目,部署信息中的jar包,等其他source,并不是在默认的文件夹下,如jar包默认在ilb下,所以需要重新修改并指定.
当然你可以直接弄成war包扔到tomcat下运行也是可以的,但牺牲了热部署.修改后的org.eclipse.wst.common.component文件信息如下:
<?xml version="1.0" encoding="UTF-8"?> <project-modules id="moduleCoreId" project-version="1.5.0"> <wb-module deploy-name="CredoBase"> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/lib" source-path="/target/credobase/WEB-INF/lib"/> <property name="context-root" value="CredoBase"/> <property name="java-output-path" value="/CredoBase/target/classes"/> </wb-module> </project-modules>