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
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