DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Glassfish 3.1.1 OSE with Hibernate Validator 4.3.0.Final

Glassfish 3.1.1 OSE with Hibernate Validator 4.3.0.Final

Peter Butkovic user avatar by
Peter Butkovic
·
Nov. 18, 12 · Interview
Like (0)
Save
Tweet
Share
2.35K Views

Join the DZone community and get the full member experience.

Join For Free
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.
http://stackoverflow.com/questions/10548931/how-to-upgrade-the-hibernate-validator-4-3-0-final-to-the-glassfish-3-1-2

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):
  • https://wikis.oracle.com/display/GlassFish/V3Jsr303BeanValidationIntegration
  • http://weblogs.java.net/blog/editor/archive/2010/04/06/arun-gupta-how-create-osgi-bundles-using-netbeans-deployment-glassfis?force=760
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 -->
     <packaging>jar</packaging>
     <properties>
-      <hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
+      <hibernate-validator.version>4.3.0.Final</hibernate-validator.version>
       <javax.validation.version>1.0</javax.validation.version>
       <slf4j.version>1.6.1</slf4j.version>
+      <jboss-logging.version>3.1.0.CR2</jboss-logging.version>
     </properties>
     <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 @@
                         <Embed-Dependency>
                             <!-- 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
                         </Embed-Dependency>
                         <Export-Package>
                              <!-- 
@@ -105,7 +106,7 @@
 
                         <Private-Package>
                              <!-- 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.*
                         </Private-Package>
 
                         <Import-Package>
@@ -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,
                            *
                        </Import-Package>
@@ -263,6 +270,13 @@
         </dependency>
 
 
+	<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 -->
         <dependency>
            <groupId>org.slf4j</groupId>
  • 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.
GlassFish Hibernate

Published at DZone with permission of Peter Butkovic, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Importance of Delegation in Management Teams
  • Beginners’ Guide to Run a Linux Server Securely
  • Asynchronous HTTP Requests With RxJava
  • Why Open Source Is Much More Than Just a Free Tier

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: