简单的JSF webapp在tomcat 7上运行,而不是在Openshift上的JBoss EWS 2.0上运行

时间:2014-11-25 14:58:51

标签: jsf tomcat jboss openshift jsf-2.2

我一直未能在Openshift的JBoss EWS 2.0盒式磁带中制作简单的MyFaces 2.2 / DeltaSpike 1.1.0 / PrimeFaces 5.1 / Weld 2.2.0.Final工作。

据我了解,此盒式磁带应该提供一个Tomcat 7容器。

当我下载tomcat 7.0.54 binary distrib时,将其解压缩并在我的主机上调试或运行我的应用程序,它就可以了。

当我尝试在OpenShift上启动相同的应用时#39; JBoss EWS 2.0(以日志状态为tomcat 7.0.54),它并没有真正运行。

我有一个简单的xhtml测试文件,accueil.xhtml,其中包含:

    <h:form>
        <p:panelGrid columns="1">
            <!-- ok -->
            <h:outputText value="Hello JSF World !"/>

            <!-- ok -->
            <h:outputText value="#{'test3'}"/>

            <!-- ok -->
            <h:outputText value="#{facesContext.externalContext.requestContextPath}"/>

            <!-- ok -->
            <h:outputText value="#{facesContext.externalContext.contextName}"/>

            <!-- ko -->
            <h:outputText value="#{testBean.test1}"/>

            <!-- ko -->
            <h:outputText value="#{testBean.uneMethode('Test2')}"/>
        </p:panelGrid>
    </h:form>

最后两个输出只是空的。

豆死了很简单:

@Named
@SessionScoped
public class TestBean implements Serializable {
    @Getter
    private String test1 = "Test1";

    public String uneMethode(String test) {
        return "Une Methode : " + test;
    }
}

(我首先想测试@ViewAccessScoped,但是回到@SessionScoped,只是为了检查pb是不是特定于第一个范围处理)。

我的context.xml也很简单:

<Context docBase="ROOT" path="/ROOT" reloadable="true" allowCasualMultipartParsing="true" jndiExceptionOnFailedWrite="false" >
    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
    <Resource name="BeanManager"
        auth="Container"
        type="javax.enterprise.inject.spi.BeanManager"
              factory="org.jboss.weld.resources.ManagerObjectFactory">
    </Resource>
</Context>

我试图定义一个docBase和一个路径,但如果没有它也会失败。

我的web.xml也很标准:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0"
         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-app_3_0.xsd">

     <display-name>Test application</display-name>
    <welcome-file-list>
        <welcome-file>accueil.xhtml</welcome-file>
    </welcome-file-list>


    <context-param>
        <param-name>primefaces.SUBMIT</param-name>
        <param-value>true</param-value>
    </context-param>
    <!-- JSF standard parameters -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            If this parameter is set to true and the submitted value of a component is
            the empty string, the submitted value will be set to null
        </description>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>State saving method: "client" or "server" (= default)
            See JSF Specification 2.5.3</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <!-- MyFaces specific parameters -->
    <context-param>
        <description>Only applicable if state saving method is "server" (= default).
            Defines the amount (default = 20) of the latest views are stored in session.</description>
        <param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
        <param-value>20</param-value>
    </context-param>
    <context-param>
        <description>Only applicable if state saving method is "server" (= default).
            If true (default) the state will be serialized to a byte stream before it
            is written to the session.
            If false the state will not be serialized to a byte stream.</description>
        <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>Only applicable if state saving method is "server" (= default) and if
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (= default)
            If true (default) the serialized state will be compressed before it
            is written to the session. If false the state will not be compressed.</description>
        <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>This parameter tells MyFaces if javascript code should be allowed in the
            rendered HTML output.
            If javascript is allowed, command_link anchors will have javascript code
            that submits the corresponding form.
            If javascript is not allowed, the state saving info and nested parameters
            will be added as url parameters.
            Default: "true"</description>
        <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <description>If true, rendered HTML code will be formatted, so that it is "human readable".
            i.e. additional line separators and whitespace will be written, that do not
            influence the HTML code.
            Default: "true"</description>
        <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>If true, a javascript function will be rendered that is able to restore the
            former vertical scroll on every request. Convenient feature if you have pages
            with long lists and you do not want the browser page to always jump to the top
            if you trigger a link or button action that stays on the same page.
            Default: "false"</description>
        <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
        <param-value>true</param-value>
    </context-param>
    <!-- desactivation du support des JSP (voir https://issues.apache.org/jira/browse/MYFACES-3078 )-->
    <context-param>
        <param-name>org.apache.myfaces.SUPPORT_JSP</param-name>
        <param-value>false</param-value>
    </context-param>
    <!-- ne jamais relire les fichiers XHTML -->
    <context-param>
        <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
        <param-value>-1</param-value>
    </context-param>
    <!-- aucun check de duplicité d'id en prod (voir http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_CHECK_ID_PRODUCTION_MODE) -->
    <context-param>
        <param-name>org.apache.myfaces.CHECK_ID_PRODUCTION_MODE</param-name>
        <param-value>false</param-value>
    </context-param>
    <!-- voir http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_VIEW_UNIQUE_IDS_CACHE_ENABLED -->
    <context-param>
        <param-name>org.apache.myfaces.VIEW_UNIQUE_IDS_CACHE_ENABLED</param-name>
        <param-value>true</param-value>
    </context-param>
    <!-- voir http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_CACHE_EL_EXPRESSIONS -->
    <context-param>
        <param-name>org.apache.myfaces.CACHE_EL_EXPRESSIONS</param-name>
        <param-value>strict</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/</param-value>
    </context-param>
    <!-- voir http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_SAVE_STATE_WITH_VISIT_TREE_ON_PSS -->
    <context-param>
        <param-name>org.apache.myfaces.SAVE_STATE_WITH_VISIT_TREE_ON_PSS</param-name>
        <param-value>true</param-value>
    </context-param>

    <listener>
        <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
    </listener>
     <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>    
    <resource-env-ref>
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
    </resource-env-ref>

</web-app>

我的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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>testlp</groupId>
        <artifactId>testlp</artifactId>
        <packaging>war</packaging>
        <version>1.0</version>
        <name>testlp</name>
        <repositories>
                <repository>
                        <id>eap</id>
                        <url>http://maven.repository.redhat.com/techpreview/all</url>
                        <releases>
                                <enabled>true</enabled>
                        </releases>
                        <snapshots>
                                <enabled>true</enabled>
                        </snapshots>
                </repository>
        </repositories>
        <pluginRepositories>
                <pluginRepository>
                        <id>eap</id>
                        <url>http://maven.repository.redhat.com/techpreview/all</url>
                        <releases>
                                <enabled>true</enabled>
                        </releases>
                        <snapshots>
                                <enabled>true</enabled>
                        </snapshots>
                </pluginRepository>
        </pluginRepositories>
        <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <maven.compiler.source>1.7</maven.compiler.source>
                <maven.compiler.target>1.7</maven.compiler.target>
        </properties>
        <dependencies>
<!--
                <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>9.2-1003-jdbc4</version>
                </dependency>
-->
    <!-- JSF -->
    <dependency>
      <groupId>org.apache.myfaces.core</groupId>
      <artifactId>myfaces-api</artifactId>
      <version>2.2.6</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.myfaces.core</groupId>
      <artifactId>myfaces-impl</artifactId>
      <version>2.2.6</version>
      <!-- on prend toujours ce package afin d'avoir acces a ViewNotFoundException 
      <scope>runtime</scope>-->
    </dependency>

    <!-- Specifications -->
    <!-- JSR-330 -->
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-atinject_1.0_spec</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
    </dependency>

    <!-- JSR-299 -->
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-jcdi_1.0_spec</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-jta_1.1_spec</artifactId>
      <version>1.1.1</version>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-interceptor_1.1_spec</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-validation_1.0_spec</artifactId>
      <version>1.1</version>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-servlet_3.0_spec</artifactId>
      <version>1.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-el_2.2_spec</artifactId>
      <version>1.0.4</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-jsp_2.1_spec</artifactId>
      <version>1.0.1</version>
    </dependency>

    <dependency>
      <groupId>org.apache.myfaces.buildtools</groupId>
      <artifactId>myfaces-builder-annotations</artifactId>
      <version>1.0.9</version>
    </dependency>

    <dependency>
      <groupId>dom4j</groupId>
      <artifactId>dom4j</artifactId>
      <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>2.2.0.Final</version>
    </dependency>
    <!-- primefaces -->
    <dependency>
      <groupId>org.primefaces</groupId>
      <artifactId>primefaces</artifactId>
      <version>5.1</version>
      <type>jar</type>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.14.4</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.deltaspike.core</groupId>
        <artifactId>deltaspike-core-api</artifactId>
        <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.core</groupId>
        <artifactId>deltaspike-core-impl</artifactId>
        <version>1.1.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-jsf-module-api</artifactId>
        <version>1.1.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-jsf-module-impl</artifactId>
        <version>1.1.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-security-module-api</artifactId>
        <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-security-module-impl</artifactId>
        <version>1.1.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-bean-validation-module-api</artifactId>
        <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.deltaspike.modules</groupId>
        <artifactId>deltaspike-bean-validation-module-impl</artifactId>
        <version>1.1.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
       <groupId>org.apache.deltaspike.modules</groupId>
       <artifactId>deltaspike-servlet-module-api</artifactId>
       <version>1.1.0</version>
       <scope>compile</scope>
   </dependency>

   <dependency>
       <groupId>org.apache.deltaspike.modules</groupId>
       <artifactId>deltaspike-servlet-module-impl</artifactId>
       <version>1.1.0</version>
       <scope>runtime</scope>
   </dependency>
            <dependency>
               <groupId>org.apache.tomcat</groupId>
               <artifactId>tomcat-el-api</artifactId>
               <version>7.0.54</version>
               <scope>provided</scope>
           </dependency>
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jasper-el</artifactId>
                <version>7.0.54</version>
               <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>javax.el</groupId>
                <artifactId>el-api</artifactId>
                <version>2.2</version>
               <scope>provided</scope>
            </dependency>

        </dependencies>
        <profiles>
                <profile>
                        <!-- When built in OpenShift the 'openshift' profile will be used when 
                                invoking mvn. -->
                        <!-- Use this profile for any OpenShift specific customization your app 
                                will need. -->
                        <!-- By default that is to put the resulting archive into the 'webapps' 
                                folder. -->
                        <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
                        <id>openshift</id>
                        <build>
                                <finalName>testlp</finalName>
                                <plugins>
                                        <plugin>
                                                <artifactId>maven-war-plugin</artifactId>
                                                <version>2.1.1</version>
                                                <configuration>
                                                        <outputDirectory>webapps</outputDirectory>
                                                        <warName>ROOT</warName>
                                                </configuration>
                                        </plugin>
                                </plugins>
                        </build>
                </profile>
        </profiles>
</project>

beans.xml几乎为空:

<beans  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/beans_1_0.xsd" />

还有faces-config.xml:

<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
              version="2.2">
    <application>
        <locale-config>
            <default-locale>fr_FR</default-locale>
            <supported-locale>fr</supported-locale>
        </locale-config>
    </application>
</faces-config>

但我发现服务器日志存在以下差异。在当地,我有:

INFO: Initialize Weld using ServletContainerInitializer
nov. 25, 2014 3:23:20 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.2.0 (Final)
nov. 25, 2014 3:23:20 PM org.jboss.weld.bootstrap.WeldStartup startContainer

在OpenShift设备上,我有:

INFO: Initialize Weld using ServletContainerInitializer
Nov 25, 2014 9:21:33 AM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.2.0 (Final)
Nov 25, 2014 9:21:34 AM org.jboss.weld.environment.servlet.deployment.URLScanner handleURL
WARN: Not implemented.
Nov 25, 2014 9:21:35 AM org.jboss.weld.bootstrap.WeldStartup startContainer

JBoss部署WAR的方式有问题吗?我读过VFS的错误问题......

欢迎任何帮助!

0 个答案:

没有答案