如何使用GlassFish 4.0推送Primefaces 5?

时间:2014-07-17 00:36:27

标签: jsf primefaces glassfish-4

我在eclipse上创建了一个示例,使用glassfish 4.0推送primefaces 5。我复制了primefaces的推送代码(http://www.primefaces.org/showcase/push/chat.xhtml)。我在pom.xml中配置如下:

  

的pom.xml

   <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warSourceDirectory>webapp</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
    <finalName>${project.artifactId}</finalName>
</build>

<repositories>
    <repository>
        <id>prime-repo</id>
        <name>PrimeFaces Maven Repository</name>
        <url>http://repository.primefaces.org</url>
        <layout>default</layout>
    </repository>
</repositories>
<dependencies>
    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <!-- Faces Implementation -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.4</version>
    </dependency>
    <!-- Faces Library -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.4</version>
    </dependency>
    <!-- Primefaces Version 5 -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.0</version>
    </dependency>

    <!-- Atmosphere -->
    <dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-runtime</artifactId>
        <version>2.1.3</version>
    </dependency>        
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
      </dependency>

    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
    </dependency>

<!-- File Upload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.2</version>
    </dependency>

    <!-- JSP Library -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <!-- JSTL Library -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.1.2</version>
    </dependency>
</dependencies>

和web.xml:

    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <servlet>
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <async-supported>true</async-supported>
   </servlet>



<servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.xhtml</url-pattern>
   </servlet-mapping>

<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
    <async-supported>true</async-supported>
</servlet>

<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping>

<!-- Following param only needed for MyFaces (TomEE, etc) -->
<context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

<context-param>
    <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

在我完成所有代码之后,例如,使用primefaces直接从eclipse推送和部署到glassfish 4并且出现类似下面的错误:

Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Lorg/primefaces/push/EventBus;.

请帮我找出问题并成功部署。

1 个答案:

答案 0 :(得分:0)

我是PFP / Atmosphere的新手但对我来说似乎缺少气氛API。由于我在使用Primefaces 5.1推送在Glassfish 4上工作时遇到了很多困难,我想与社区分享我的设置:)

&#13;
&#13;
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  
	<display-name>MyProject</display-name>
  
	<context-param>
	    <param-name>javax.faces.PROJECT_STAGE</param-name>
	    <param-value>Development</param-value>
	</context-param>
	
	
	<welcome-file-list>
	  	<welcome-file>login.html</welcome-file>
	</welcome-file-list>
	
	<!-- **************** FACES CONFIGURATION ******************** -->
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<async-supported>true</async-supported>
	</servlet>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.xhtml</url-pattern>
	</servlet-mapping>
  
  	<!-- **************** Primefaces PUSH (Athmosphere based)  ******************** -->
	<servlet>
	    <servlet-name>Push Servlet</servlet-name>
	    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
	    <load-on-startup>1</load-on-startup>
	    <async-supported>true</async-supported>
	</servlet>
	<servlet-mapping>
	    <servlet-name>Push Servlet</servlet-name>
	    <url-pattern>/primepush/*</url-pattern>
	</servlet-mapping>

	<!-- **************** Primefaces FILE UPLOAD  ******************** -->
	<filter>
	  <filter-name>PrimeFaces FileUpload Filter</filter-name>
	  <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
	</filter>
	<filter-mapping>
	  <filter-name>PrimeFaces FileUpload Filter</filter-name>
	  <servlet-name>Faces Servlet</servlet-name>
	</filter-mapping>
	
	
	
	
	<!-- ********* PARTIAL SUBMIT <ENABLED> ********* --> 
	<context-param>
	  <param-name>primefaces.SUBMIT</param-name>
	  <param-value>partial</param-value>
	</context-param>
	
	<!-- ********* CLIENT_SIDE_VALIDATION <ENABLED> ********* -->
	<context-param>
	  <param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>
	  <param-value>true</param-value>
	</context-param>
	
	<!-- ********* FACELETS_SKIP_COMMENTS <ENABLED> ********* -->
	<context-param>
	  <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
	  <param-value>true</param-value>
	</context-param>
	
	<context-param>
	  <param-name>primefaces.UPLOADER</param-name>
	  <param-value>auto</param-value>
	</context-param>
	
	<context-param>
	    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
	    <param-value>client</param-value>
	</context-param>
    
</web-app>
&#13;
&#13;
&#13;

我的库设置如下:WEB-INF / lib /

-primefaces-5.1.jar
-vaadin-SLF4J-jdk14-1.6.1.jar -atmosphere运行时,2.2.4.vaadin5.jar
-slf4j-API 1.7.10.jar -commons-文件上传-1.3.1.jar

注意:我使用Luna Service Release 1a(4.4.1)并且我发现当我更改设置时,我必须从服务器中删除我的应用程序,重启服务器,重新部署和项目 - &gt;清洁,以使其工作。 希望这篇文章可以提供帮助。