JSF 2.0 - could not find Factory...
Today I notice that when I deploy my JSF 2 webapp on GlassFish 3.1, i have this error :
java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory
To avoid this error message it you should add the listener "com.sun.faces.config.ConfigureListener" into the web.xml.
But you will still see the error message again if your FacesServlet has the load-on-startup option "1".
This option will avoid that the ConfigureListern is loaded before the FacesServlet starts.
So use the following setup for your web.xml file (3.0):
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="3.0">
....
<!-- ============== Configuration Listener ============== -->
<!--
This ServletContextListener initializes the runtime environment
of the JavaServer Faces Reference Implementation when a web
application including it is initialized by the container.
-->
<listener>
<listener-class>
com.sun.faces.config.ConfigureListener
</listener-class>
</listener>
....
<!-- Facelets -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
......
>
It is important to set the load-on-startup setting to 0
See also further Information here.
Posted at 10:21AM Jul 29, 2012
Posted by: Ralph
Category: General
Canging from @ManagedBean to @Named @Inject
It take me a lot of time playing arround with right usage of the JSF 2.0 annotation @ManagedBean and the Java EE6 annotation @Named.
Both of them can do the same job. I think the @Name/@Inject variant is more powerfull. You can find a usefull link here:
http://weblogs.java.net/blog/cayhorstmann/archive/2009/12/23/javaxfacesbeanmanagedbean-dead-arrival
The main problem for me was that the @Named / @Inject annotation seems not to work. After a long time playing arround with different settings and a lot of frustrating error messages I found that the problem was not the annotation, but the internal state of my GlassFish server (weld implementation).
When you have deployed an application which makes use of the @ManagedBean annotation and you change this into @Named any further deployment will fail with a lot of error messages. The reason for all this seems to be an internal state of the web container not allowing deploying/undeploying the same bean in a different context.
To get things working well it is important that you first undeploy your application using the @ManagedBean, then restart GlassFish and then deploy the new application using the @Named annotation.
Overall if you are working with manged beans and using the @Named, and @Inject annotation take care about the following things:
- Your manage bean should implement the Serializable interface
- Use the javax.enterprise.context (e.g. javax.enterprise.context.SessionScoped) not ! the javax.faces.bean.SessionScoped
- If you @Inject beans take care about providing setter and getter methods for your injected managed Bean
- Provide an empty /imixsworkflow/beans.xml file!
- Provide an empty faces-config.xml file
- Provide a default constructor
When you undeploy the old application and shutdown your GlassFish check also the application directory
/GLASSFISH_DOMAIN/applications
for any old application artefacts.
Posted at 05:55PM Jul 26, 2012
Posted by: Ralph
Category: General
Eclipse Juno - Maven support
The new Eclipse build 4.2 (Eclipse Juno) is out and I started using it for my own Maven based Java EE projects. After playing around with several plugins concerning the maven integration, I came to the conclusion that the Maven-WTP integration in Eclipse is still something you did not need and you should not use. It slows down my complete workspace containing different multi-module maven projects. Maybe its only my IDE installation of Eclipse 4.2, but I recognised a permanent CPU peak as result of a never ending WTP Builder process. After I removed the "Maven Integration for WTP" Eclipse Juno works again very fast.
So here is my recommendation for plugins that you should install in Eclipse 4.2 (Classic) if you are developing Maven based Java EE projects:
- JavaServer Faces Tools (JSF) Project (for JSF/Faclets support - much better than in Eclipse 3.7)
- JST Server Adapters (for GlassFish Server Adapters - see also my blog about GlassFish 3.2 support)
- m2e - Maven Integration for Eclipse (the general and pure maven integration)
- Subversive Integration for the M2Eclipse Project (necessary if you work with SVN - see another blog entry)
And do not install the "Maven Integration for WTP" plugin.
If you are looking for a simple Hotdeployment Plugin for Eclipse/GlassFish take a look at Manik hot-deploy.
Posted at 04:09PM Jul 22, 2012
Posted by: Ralph
Category: General
Why is my JSF 2.0 managed Bean not working....
Today I run again into a problem when a managed bean was not working in my new JSF 2.0 application. I added the bean into a page element using expression language.
<h2>
<h:outputText value="#{loginMB.remoteUser}" />
</h2>
But my bean was never called. The special part is that in my case the loginMB is part of an jar which was added as a library into the web module. The bean itself is annotated as followed:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
....
@ManagedBean
@SessionScoped
public class LoginMB {
...
}
In this szenario it is necessary to add an empty faces-config.xml descriptor into the META-INF folder of the jar. Otherwise the bean will not be detected by the web container:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config 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-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
In different to the faces-config.xml file an empty bean.xml file is optional.
@ManagedProperty
If your managed bean injects other manged beans uses the annotation @ManagedProperty
@ManagedProperty(value = "#{loginMB}")
private LoginMB loginMB = null;
public LoginMB getLoginMB() {
return loginMB;
}
public void setLoginMB(LoginMB loginMB) {
this.loginMB = loginMB;
}
In this case a setter and getter method for the field 'loginMB' must be provided!
Posted at 07:45AM Jul 22, 2012
Posted by: Ralph
Category: General
Eclipse Juno - JST & Glassfish
The J2EE Server Tools providing a comfortable way to integrate the Java EE Servers (e.g. GlassFish) into the Eclipse IDE. For the latest release of Eclipse (4.2 - Juno) the integration is a little bit tricky.
First you need to instal the JST plugin via menu "Help>install new Software" and search for "server". Select the "JST Server Adapters" and install it.
Next you need to add a extra update site to install the latest GlassFish adapters. Add the followin Update Site URL:
http://download.java.net/glassfish/eclipse/juno
Read also the following blog from Vince Kreamer for deails:
https://blogs.oracle.com/vkraemer/entry/internal_3_1_2_runtime
Posted at 11:04AM Jul 21, 2012
Posted by: Ralph
Category: General
Eclipse Juno - Maven & Subversion
The new Eclipse release (4.2) is out and looks great! To run a first IDE test I tried to checkout some maven projects from my svn repository. M2E and the Subversive Plugin are not installed in the Eclipse classic platform (can't understand why) but can be easily installed manually from the menu "->Help->install new Software"
After restarting Eclipse you can start importing your maven project with "->File->new-> project->Checkout Maven Projects form SCM"
The problem here is hat the SVN connector for m2e is missing and can not be installed by the dialog showing up all available maven add ons. To solve this problem go again to install new software manually and add the following update URL:
http://community.polarion.com/projects/subversive/download/integrations/update-site/
This updatesite includes the missing svn/m2e connector. After a restart you can checkout your maven project from a SVN repository using the Eclispe subversive plugin.
Posted at 10:42AM Jul 21, 2012
Posted by: Ralph
Category: General
JSF 2.0 and the xmlns:c
If you are working with JSF 2.0 there is a important change concerning the JSF core tags (<c:....>). These tags will not work if you are using the following namespace declaration:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html">
This works in JSF 1.2 but well, but did no longer work in JSF 2.0. The reason is that the namespace uri for the jstl/core has changed. Use the following namespace definition if you are working with jsf 2.0
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:h="http://java.sun.com/jsf/html">
Posted at 09:27PM Jul 20, 2012
Posted by: Ralph
Category: General
Glassfish - 3.1.x - CDIExtension not found
Today I run into a problem when trying to deploy a EAR with more than one web modules using CDI. Deploying such a EAR on Glassfish 3.1.1 or 3.1.2 will fail with the following exception:
Root exception is javax.naming.NameNotFoundException: CDIExtension not found
As you can read in this posting this is a known bug.
http://java.net/jira/browse/JERSEY-601
You can solve the problem when setting the system-property "com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true".
This can be done from the GlassFish server console.
- Select the node ->Configuration->server-config->JVM Settings
- change to the tab 'JVM Options'
- add a new entry
-Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
- restart your server
This will solve the deployment problem.
Posted at 09:04PM Jul 20, 2012
Posted by: Ralph
Category: General
Rest Service and the HttpServletRequest
Today I got a strange problem with my REST service which needs a HttpServletRequest object to perform the RemoteUser name.
First I injected the HttpServletRequest as a field into my RestService-Class
....
@Path("/")
@Produces({ "text/html", "application/xml", "application/json" })
@Stateless
public class SystemRestService {
...
@javax.ws.rs.core.Context
private static HttpServletRequest servletRequest;
.....
This works fine on my local glassfish server 3.1.1. But after I deployed this into my productive environment (glassfish 3.1) the field 'servletRequest' was always null.
The problem here is that injecting the HttpServletRequest into an instance field can become very soon stale. The solution is to annotating a method parameter to assure that the request object is obtained in connection to processing a request.
...
@GET
@Path("/profile.json")
@Produces("application/json")
public String getUserByID(@QueryParam("uid") String user,
@QueryParam("items") String items,@Context HttpServletRequest servletRequest) {
.....
See also this discussion on the coderanch:
http://www.coderanch.com/t/510941/Web-Services/java/Print-Client-IP#2649412
Posted at 10:16AM May 27, 2012
Posted by: Ralph
Category: General
JUnit and Glassfish 3.1.1 - Remote EJB tests
Trying to run a JUnit Test with remote EJB lookups from a GlassFish server 3.1.1 it is a little bit tricky. It seems to me that it is not possible to get the maven dependencies working. The gf_client.jar can not be included using a dependency, although the artefact can be located using the glassfish repository from java.net :
.....
<!-- Glassfish -->
<repository>
<id>glassfish-repository</id>
<name>Java.net
Repository for Glassfish</name>
<url>http://download.java.net/maven/glassfish</url>
</repository>
.....
..and adding a dependecy:
...
<dependency>
<groupId>org.glassfish.appclient</groupId>
<artifactId>gf-client</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
....
But after all this wont work for me. So the best way is to add the gf_client.jar directly into your classpath.
The gf_client.jar is located in your Glassfish Installation at
$GLASSFISH_HOME/glassfish/lib/gf-client.jar
Now you can write a JUnit test with a remot ejb lookup. See the following example for a remote lookup to Imixs Entity Service
public class TestEntityService {
EntityServiceRemote entityService = null;
@Before
public void setup() {
try {
// set jndi name
String ejbName = "java:global/imixs-workflow-web-sample-0.0.5-SNAPSHOT/EntityService!org.imixs.workflow.jee.ejb.EntityServiceRemote";
InitialContext ic = new InitialContext();
entityService = (EntityServiceRemote) ic.lookup(ejbName);
} catch (Exception e) {
e.printStackTrace();
entityService = null;
}
}
@Test
@Category(org.imixs.workflow.jee.ejb.EntityServiceRemote.class)
public void testService() {
Assert.assertNotNull(entityService);
//....
}Note: To run this JUnit test you have to first deploy your test application. After that you junit test can be run.
Testing secured EJBs
If your remote ejb is annotated with the security annotation @RolesAllowed you need to authenticate your remote lookup.
In GlassFish this can be done using the programmatic Login. To setup a programmatic login in your JUnit test first create a File named 'auth.conf'. The content of that file should look like this:
default {
com.sun.enterprise.security.auth.login.ClientPasswordLoginModule required debug=false;
};
Now you can add the programmatic login into your test setup
@Before
public void setup() {
try {
// set jndi name
String ejbName = "java:global/imixs-workflow-web-sample-0.0.5-SNAPSHOT/EntityService!org.imixs.workflow.jee.ejb.EntityServiceRemote";
// setup programmatic login for GlassFish 3
System.setProperty("java.security.auth.login.config", "/home/rsoika/eclipse_37/imixs-workflow/imixs-workflow-engine/src/test/resources/auth.conf");
ProgrammaticLogin programmaticLogin = new ProgrammaticLogin();
// set password
programmaticLogin.login("Anna", "anna");
InitialContext ic = new InitialContext();
entityService = (EntityServiceRemote) ic.lookup(ejbName);
} catch (Exception e) {
e.printStackTrace();
entityService = null;
}
}
Note: the username/password is defined in this case in a file realm which is the default security realm of my GlassFish
Here are some helpful links:
http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB
http://www.coderanch.com/t/476090/EJB-JEE/java/EJB-Realms-Remote-Clients
Posted at 09:08PM May 16, 2012
Posted by: Ralph
Category: General
GlassFish - HeapSize settings
After playing around with some VM settings in my GlassFish 3.1.1 environment (development and productive) I came to a setup which brings up my glassfish server much faster. Here are my settings
Development (3GB RAM)
-client
-XX:+AggressiveHeap
-Xmx1024m
-Xms1024m
-Xss128k
-XX:+DisableExplicitGC
Productiv (4GB Ram)
-server
-XX:+AggressiveHeap
-Xmx2048m
-Xms2048m
-Xss128k
-XX:+DisableExplicitGC
Here is also a useful link for further performance settings:
Posted at 04:32PM May 05, 2012
Posted by: Ralph
Category: General
GlassFish - EJB Timer Service not available
Today I had a situation where after a hardware crash my GlassFish Server did not work correctly. Specially the timer service did no longer work. The server log shows a lot of errors about
...EJB Timer Service not available
In the easiest case the reason why the timer service did not start are old db.lck files.
You can check this by stopping the server and then look for any lock files in the domain folder
../lib/databases/ejbtimer/
After removing the files
dbex.lck
db.lck
you can restart the server and every thing should work again.
See also the following thread if this did not work for you:
http://forums.java.net/node/666385
Posted at 03:23PM Apr 23, 2012
Posted by: Ralph
Category: General
Character encoding de_DE on Linux Debian
On my debian server today I run into a problem with the encoding of XSL templates running on a GlassFish server. The problem was that German characters where not displayed correctly.
After a long time of searching, I figured out that the reason for that problem was not my MySQL database, nor my GlassFish installation. It was simply the missing German language support on my linux debian.
You can test the installed locales with the following command:
locale -a
In my case only 'en_US.utf8' was listed.
In debian you can simply add the german language support by changing the file /etc/locale.gen. Simply uncomment the lines:
de_DE ISO-8859-1
de_DE.UTF-8 UTF-8
de_DE@euro ISO-8859-15
and run the command:
locale-gen
After restarting my GlassFish server the xsl transformation works fine with german characters.
The command "locale -a" now displays the following locale:
C
de_DE
de_DE@euro
de_DE.iso88591
de_DE.iso885915@euro
de_DE.utf8
deutsch
en_US.utf8
german
POSIX
Posted at 12:18PM Jan 23, 2012
Posted by: Ralph
Category: General
Eclipse and Gnome Shell
Today I stumbled into a problem with my eclipse IDE running in Ubuntu 11.04 with Gnome shell. When trying to run the BIRT plugin with external XML resources the popup dialog prompting for username/password did no longer appear and I got a http error message 401. I think similar problems can also appear with other plugins in eclipse or eclipse based applications.
To solve such a problem it is necessary to provide a customized startup script. To create such a script change into the folder were your eclipse is installed and create a new file named 'eclipse_gnome'
Next make it executable by running the command
chmod +x ~/eclipse_gnome
Now edit the file with the following lines of code
#!/bin/sh
export GDK_NATIVE_WINDOWS=true
./eclipse
With the GDK_NATIVE_WINDOWS variable eclipse changes the way to handle windows internal. And this will fix difernt problems working with eclipse in Gnome shell.
To start eclipse use the new script.
If you have installed eclipse through the ubuntu software-center then your eclipse executable is located in the folder /usr/lib/eclipse/eclipse. In that case you can change the content of your start script like this:
#!/bin/sh
export GDK_NATIVE_WINDOWS=true
/usr/lib/eclipse/eclipse
Posted at 06:23PM Jan 12, 2012
Posted by: Ralph
Category: General
Gnome3 - Anpassen
Gnome3 - Titelleiste von Anwendungen im maximierten Zustand aublenden [Read More]
Posted at 09:59AM Nov 12, 2011
Posted by: Ralph
Category: General