I followed Markus Eisele’s great article on creating a JDBCRealm in Glassfish – jdbc-realm-glassfish312-primefaces342.html.

However I tried getting this to work by building in Eclipse instead of Netbeans and it proved not so straight-forward. It turns out that the extra work was minimal; it just took me a little effort to work this out.

Increase log levels

My first advice when you have no idea of what is going on with your JEE deployed application is to increase the log levels on your application server – Glassfish in this case. Find them at:

Glassfish > Configurations > Server-config > Logger Settings > Log Levels (tab)

Differences between Netbeans and Eclipse

Netbeans ‘just works’, but at the cost of some flexibility and power. Eclipse is Fucken awesome, with awesome (or large) being the operative word.

For example is this case (and which is the main difference I’m discussing).

The deployment descriptor glassfish-resources.xml is used to setup the JDBC Connector and Resource. Unfortunately, as I learnt, its not a deployment descriptor in the sense that it is read by the Application Server (Glassfish here) when its in the WEB-INF or META-INF directory.

What Netbeans does is run the following under-the-hood.


asadmin add-resources WEB-INF/glassfish-resources.xml

And that precisely is what you need to do when developing this using Eclipse. Either that or define the JDBC Connector and Resource manually in Glassfish. However its better to move such actions to a file that can be replayed (which you need to do after you remove and re-add the Glassfish server in Eclipse which I seem to need to do every now and then).

Other gotchas

Other steps needed as modifications to Markus’ article are:

  • Database configuration can’t be done through the IDE to the same extent – use MySQL Workbench or just the mysql command-line for MySQL, or whatever tools for your database of choice.
  • The section on JDBC Connector and Resource and Extract from Existing Connection to creaqte the glassfish-resources.xml doesn’t have a counterpart in Eclipse. Instead either do in Netbeans and copy the contents to a new xml file in the WEB-INF directory, or create the same file from an example on the web (eg. http://javahowto.blogspot.com.au/2011/02/sample-glassfish-resourcesxml.html) and populate with your values.
  • The Additionally we still need Primefaces part doesn’t need a fancy wizard with a checkbox. Simply add Primefaces as a dependency in your Maven pom. Group=org.primefaces, Artifact=primefaces, Version=3.4.2 (current)
  • For the jsf / xhtml files, just create html files and select the Facelets Composite Page (WTP needs to be installed). Or simply create a file called whatever.xhtml in the appropriate directory. Then just populate with what’s in Markus’ article.
  • The New > Other > GlassFish > GlassFish Descriptor” section just requires you create a WEB-INF/glassfish-web.xml file and populate with the given <security-role-mapping>
Written on June 13th, 2013 , authentication, Java, JSF Tags: , ,

Brooke Smith is proudly powered by WordPress and the Theme Adventure by Eric Schwarz
Entries (RSS) and Comments (RSS).

Brooke Smith

Portfolio and site of a software engineer