在Jboss EAP 6/Wildfly中使用Hibernate 3和JSF 1.2
在EAP 6中使用JSF1.2
增加jboss-deployment-structure.xml文件,其内容如下:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="javax.faces.api"/>
<module name="com.sun.jsf-impl"/>
</exclusions>
<dependencies>
<module name="javax.faces.api" slot="1.2" export="true"/>
<module name="com.sun.jsf-impl" slot="1.2" export="true"/>
</dependencies>
</deployment>
<sub-deployment name="xxx.war">
<exclusions>
<module name="javax.faces.api"/>
<module name="com.sun.jsf-impl"/>
</exclusions>
<dependencies>
<module name="javax.faces.api" slot="1.2"/>
<module name="com.sun.jsf-impl" slot="1.2"/>
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
以上为EAP包中的配置,注意web sub deployment要再配置一遍。如为WAR仅需最外层就可以喽。
在EAP 6 中使用Hibernate 3
1. pom配置
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
<exclusions>
<exclusion>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</exclusion>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.10.Final</version>
<exclusions>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.1.0.GA</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
2. jboss-deployment-structure.xml文件配置
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="org.hibernate" slot="main" />
</exclusions>
<dependencies>
<module name="org.apache.commons.logging" />
<module name="org.apache.commons.collections" />
<module name="org.apache.log4j" />
<module name="org.dom4j" />
<module name="org.slf4j" />
<module name="org.antlr" />
<module name="asm.asm" />
<module name="org.javassist" />
</dependencies>
</deployment>
</jboss-deployment-structure>
3. persistence.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/defaultDS</jta-data-source>
<properties>
<!-- 注意要使用hibernate3-bundled -->
<property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
EAP支持的JPA版本,请查看源码,位于模块org\jboss\as\jpa\jboss-as-jpa.jar的org.jboss.as.jpa.config.Configuration类中。
Wildfly
Wildfly默认不支持JSF1.2,如要使用需下载Wildfly源码编译安装。
1) cd <WILDFLY_SOURCE_ROOT>/jsf/multi-jsf-installer
2) mvn -Djsf-version=1.2_15 -Pmojarra-1.2 clean assembly:single
3) The final artifact in the target directory will be called install-mojarra-1.2_15.zip. Rename it to install-mojarra-1.2_15.cli.
4) Start WildFly
5) cd to <JBOSS_HOME>/bin for the running server where you want to install the new JSF.
6) Start the Command Line Interface and invoke this command then restart WildFly.
jboss-cli.bat --connect
[standalone@localhost:9990 /]deploy <local path to archive>/install-mojarra-1.2_15.cli
执行完以上命令后,JSF1.2安装在modules根目录下,slot为mojarra-1.2_15,需要手工修改和迁移一下(共三个模块:javax\faces\api,com\sun\jsf-impl,org\jboss\as\jsf-injection)
再修改一下配置:
<exclusions>
<module name="javax.faces.api"/>
<module name="com.sun.jsf-impl"/>
<module name="org.jboss.as.jsf-injection"/>
</exclusions>
<dependencies>
<module name="javax.faces.api" slot="1.2" export="true"/>
<module name="com.sun.jsf-impl" slot="1.2" export="true"/>
<module name="org.jboss.as.jsf-injection" slot="1.2" export="true"/>
</dependencies>
注意必须增加jsf-injection,否则启动后会报以下错误:
java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Class javax.faces.FactoryFinder can not access a member of class org.jboss.as.jsf.injection.weld.WeldApplicationFactory with modifiers "private"
How to Use Hibernate 3 in EAP 6
Steps to add any new JSF implementation or version to WildFly
上一篇: 3D游戏编程作业8
下一篇: JDK 8 静默安装