SQL Zone is brought to you in partnership with:

I'm a java developer living in the Munich area. Prototyping is for me the most favourite part of the project work (especially in the phase when nobody really knows if things are really gonna work :) I'm also quite influenced by the ideas of open source software. And important things except that? Family, friends and Jesus Christ (the best Friend :). Peter is a DZone MVB and is not an employee of DZone and has posted 9 posts at DZone. You can read more from them at their website. View Full User Profile

Glassfish 3.1.1 OSE with Hibernate Validator 4.3.0.Final

  • submit to reddit
Goal: Use hibernate validator 4.3.0.Final with Glassfish 3.1.1 OSE.

Lately I came across an issue, that I wasn't able to use the latest stable hibernate validator (hiberante validator 4.3.0.Final) with Glassfish 3.1.1 OSE.

Problem is that older version is beeing used as a glassfish module (glassfish/modules/bean-validator.jar). If you check the contents of the package (in MANIFEST.MF) you'd see that version 4.1.0.Final is beeing used.

OK, so how to deal with that? I've found out that I'm not the only one having issue here.

Suggestion gave me some motivation, as it seems to be possible to achieve :)

As I'm using ear, the simple solution provided in answer was not feasable for me (as it was a war case). OK, let's see how far we can get. There are multiple references (finally I ended up with the following 2 links):
I read the later one, as it seemd like a good idea to learn creating modules deployable to glassfish, however even if I created maven osgi bundle it neither contained all the dependencies required nor the descriptor seemed to be OK. Sounds like a wrong way for me then.

Going back to the 1.st link, I found following svn repository and tried to build things: https://svn.java.net/svn/glassfish~svn/trunk/external/source-build
However only once it has been achieved (and the way there was quite long) I realized that this just rebuilds the hibernate validator with it's dependencies, and that is of course not needed, as these are already built and available in public maven repositories :).

OK, going via next steps in the article, I ended up with the following solution:
  • checked out glassfish sources:
svn co https://svn.java.net/svn/hk2~svn/branches/hk2-gf-3.1.1/
  • updated bean-validation related pom, see my diff:
Index: pom.xml
--- pom.xml	(revision 4105)
+++ pom.xml	(working copy)
@@ -54,9 +54,10 @@
          maven-bundle-plugin and hk2-maven-plugin together -->
-      <hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
+      <hibernate-validator.version>4.3.0.Final</hibernate-validator.version>
+      <jboss-logging.version>3.1.0.CR2</jboss-logging.version>
     <name>Validation API (JSR 303) version ${javax.validation.version}, Hibernate Validator version ${hibernate-validator.version} and its dependencies repackaged as OSGi bundle</name>
@@ -89,7 +90,7 @@
                             <!-- Only specify root artifacts that need to be embedded, everything else
                                  will be pulled in automatically based on Private-Package settings. -->
-                            *; artifactId=hibernate-validator|slf4j-api|slf4j-jdk14; inline=true
+                            *; artifactId=hibernate-validator|jboss-logging|slf4j-api|slf4j-jdk14; inline=true
@@ -105,7 +106,7 @@
                              <!-- Have a private copy of external non-standard dependencies -->
-                             org.slf4j.*; com.googlecode.jtype.*; org.joda.time.*; org.jsoup.*
+                             org.jboss.logging.*; org.slf4j.*; com.googlecode.jtype.*; org.joda.time.*; org.jsoup.*
@@ -117,6 +118,12 @@
                                which is a JPA 2 class.
                            org.slf4j; org.slf4j.spi; org.slf4j.helpers; version=${slf4j.version}; resolution:=optional,
+                           org.jboss.logging; version=${jboss-logging.version}; resolution:=optional,
+                           org.apache.log4j;resolution:=optional,
+                           org.jboss.logmanager;resolution:=optional,
+                           com.ibm.uvm.tools;resolution:=optional,
+                           com.sun.jdmk.comm;resolution:=optional,	
+                           javax.jmdns;resolution:=optional,
                            javax.persistence.*; version="2.0"; resolution:=optional,
@@ -263,6 +270,13 @@
+	<dependency>
+		<groupId>org.jboss.logging</groupId>
+		<artifactId>jboss-logging</artifactId>
+		<version>${jboss-logging.version}</version>
+            <optional>true</optional>
+	</dependency>
         <!-- We bundle jdk binding inside this OSGi bundle -->
  • built:
cd hk2-gf-3.1.1/external/bean-validator
mvn clean install
  • copied to glassfish modules and removed old one:
rm ${GLASSFISH_HOME}/glassfish/modules/bean-validator.jar
cp hk2-gf-3.1.1/external/bean-validator/target/bean-validator-1.1.15-SNAPSHOT.jar ${GLASSFISH_HOME}/glassfish/modules/
  • done :)

Issues? well, we'll see later, during testing :) But very first try worked perfectly.

Comments? Feel free to share, as I'm not the osgi expert (yet :)), so some of my updates might ... let's say won't make too much sense.
Published at DZone with permission of Peter Butkovic, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Peter Butkovic replied on Thu, 2012/11/22 - 8:16am

after some struggling, I came to working code formatting in my article, it should be more readable now :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.