找不到工厂:javax.faces.context.FacesContextFactory - 使用嵌入式 glassfish 3.0

发布于 2024-11-07 01:25:59 字数 4061 浏览 0 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-11-14 01:25:59

我会回答我自己的问题。 :P

我将其添加到 web.xml 并工作:

<监听器类>com.sun.faces.config.ConfigureListener

这是解释问题的网页: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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文