Maven,JEE6,Tomcat 7 / Glassfish 3.1,EJB,JSF2,Hibernate / JPA和PrettyFaces

时间:2011-05-20 09:45:34

标签: hibernate jsf tomcat maven ejb

正如我的标题已经解释的那样,我想知道如何结合这些技术?

我已经尝试过组合JEE6-Maven-Glassfish-EJB-JSF2-Hibernate-PrettyFaces,但问题是glassfish mojarra实现不能被更新版本通过pom.xml替换而且包含的mojarra版本不能与prettyfaces合作。无论如何,在真正的系统上,我会更换内部罐子以使其工作。

现在我正在尝试组合JEE6-Maven-Tomcat-EJB-JSF2-Hibernate-Prettyfaces,但不知何故EJB无法正常工作。我知道Apache没有运行带有Tomcat的jsf实现,所以我在最新的mojarra实现中添加了pom中的依赖项。

tomcat还有一个奇怪的行为,我尝试在上下文路径“/”上部署一个webapp,并且使用firefox我得到tomcat startpage加载localhost:8080并且使用chrome我得到我的应用程序视图。可能是什么问题?

在这里你可以看到我的pom.xml:

<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>com.pkg</groupId>
<artifactId>App</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<name>App</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <netbeans.hint.deploy.server>Tomcat70</netbeans.hint.deploy.server>
</properties>

<repositories>
    <repository>
        <id>JBoss</id>
        <name>JBoss Repsitory</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/maven2</url>
    </repository>

    <repository>
        <id>jboss-snapshot</id>
        <url>http://snapshots.jboss.org/maven2</url>
        <releases>
        </releases>
        <snapshots>
        </snapshots>
    </repository>

    <repository>
        <url>http://download.java.net/maven/2/</url>
        <id>hibernate-support</id>
        <layout>default</layout>
        <name>Repository for library Library[hibernate-support]</name>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <exclusions>
            <exclusion>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.2.GA</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.3.0.ga</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.3.2.GA</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.5.ga</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.0.5</version>
    </dependency>

    <dependency>
        <groupId>com.ocpsoft</groupId>
        <artifactId>prettyfaces-jsf2</artifactId>
        <version>3.2.0</version>
    </dependency>

    <dependency>
        <groupId>javax.sql</groupId>
        <artifactId>jdbc-stdext</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.0.1B</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.1-b04</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.1-b04</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <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</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>
    <finalName>App</finalName>
</build>

2 个答案:

答案 0 :(得分:4)

为什么不升级GlassFish Mojarra JAR?

  • 下载新的Mojarra http://javaserverfaces.java.net/download.html
  • 关闭GlassFish 3
  • 替换Mojarra文件jsf-impl.jar和jsf-api.jar 具有新Mojarra文件的glassfishv3 / glassfish / modules目录 jsf-impl.jar和jsf-api.jar。
  • 删除glassfish / domains / domain1 / osgi-cache目录中的所有内容
  • 启动GlassFish
  • 验证字符串new Mojarra 2.x.x是否出现在GlassFish中 启动JSF应用程序时的日志文件

http://forums.netbeans.org/post-97832.html#97832

答案 1 :(得分:0)

奇怪的是,您可以从不同浏览器上的相同上下文中获取两个不同的Web应用程序。我怀疑在这一点上,一个或多个浏览器以某种方式返回缓存页面。您是否尝试在两个浏览器中清除浏览器缓存并重试?

使用Glassfish,我替换了Mojarra jar文件,这些文件与我需要的Mojarra版本捆绑在一起。这是正确的做法。

您能否详细说明JEE6的问题? Glassfish 3.1应该符合JEE6标准,那么对你来说究竟“不起作用”呢?