找不到工厂:javax.faces.context.FacesContextFactory - 使用嵌入式 glassfish 3.0
我正在尝试使用嵌入式 glassfish 3.0 运行一个简单的 jsf-2.0 教程,但不断收到此错误。一直在这个论坛和互联网上寻找解决方案,但似乎一无所获。这是 pom:
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.sandcode</groupId>
<artifactId>helloworld</artifactId>
<packaging>war</packaging>
<name>${project.artifactId}</name>
<version>1.0</version>
<repositories>
<repository>
<id>java.net.m2</id>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>java.net.glassfish.m2</id>
<url>http://download.java.net/maven/glassfish</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>glassfish-repository</id>
<name>Java.net Repository for Glassfish</name>
<url>http://download.java.net/maven/glassfish</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<!-- embedded glassfishV3 for testing -->
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.0</version>
<configuration>
<goalPrefix>glassfish</goalPrefix>
<app>target/helloworld-1.0.war</app>
<port>8080</port>
<contextRoot>test</contextRoot>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Web.xml:
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- explicitly setting the EL factory, otherwise is not working correctly under tomcat and jetty -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<!-- welcome file mapping -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
运行 mvn package 后,会生成 war 文件并启动 glassfish。但抱怨错误。在项目文件夹中,我可以看到 jsf Maven 依赖项:jsf-api-2.1.jar。
谢谢, 莎拉
I'm trying to run a simple jsf-2.0 tutorial using embedded glassfish 3.0 and keep getting this error. Have been searching solutions on this forum and the internet and seems getting no where. Here is the pom:
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.sandcode</groupId>
<artifactId>helloworld</artifactId>
<packaging>war</packaging>
<name>${project.artifactId}</name>
<version>1.0</version>
<repositories>
<repository>
<id>java.net.m2</id>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>java.net.glassfish.m2</id>
<url>http://download.java.net/maven/glassfish</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>glassfish-repository</id>
<name>Java.net Repository for Glassfish</name>
<url>http://download.java.net/maven/glassfish</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<!-- embedded glassfishV3 for testing -->
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.0</version>
<configuration>
<goalPrefix>glassfish</goalPrefix>
<app>target/helloworld-1.0.war</app>
<port>8080</port>
<contextRoot>test</contextRoot>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Web.xml:
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- explicitly setting the EL factory, otherwise is not working correctly under tomcat and jetty -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<!-- welcome file mapping -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
After I run mvn package, the war file is generated and glassfish starts up. But complains the error. In the project folder I can see the jsf Maven dependency: jsf-api-2.1.jar.
Thanks,
Sarah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会回答我自己的问题。 :P
我将其添加到 web.xml 并工作:
这是解释问题的网页:http://javawords.com/2009/06/05/using-jsf-12-with-facelets-on-google-app-engine-for- java/
看来嵌入的 glassfish 不会在启动时初始化 servlet,而是将初始化推迟到第一个请求。
莎拉
I will answer my own question. :P
I added this to web.xml and worked:
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener>
Here is the web page explains the problem: http://javawords.com/2009/06/05/using-jsf-12-with-facelets-on-google-app-engine-for-java/
It seems that the embedded glassfish does not initialize servlets at startup, instead initialization is postponed until the first request.
Sarah