Overriding the Jboss classloader
Apr 02, 2012
On the project I'm on, I have to develop against a slightly older version of Jboss (5.1.0 GA specifically), which comes with out-of-date libraries for hibernate and jpa. After some tweaking I found the following steps would let me package my own jars and override the jboss classloader. Nowhere could I find this clearly documented on the jboss website - so I hope this helps save someone some time!
1) I added this code to my app
2) i removed
from my buildpath and lib directory. the lib directory in my project holds all the jars my project needs to reference, but are currently included with jboss.
3) I added
4) I added a new file, war/web-inf/jboss-classloading.xml. here are the contents:
5) the old code at step 1) needs to be updated to: log.info("hibernate version :: " + org.hibernate.Version.getVersionString()); since hibernates api between 3 and 4 apparently changed
6) stop and restart jboss completetly and then run - the code now gives:
7) victory!
1) I added this code to my app
log.info("hibernate version :: " + org.hibernate.cfg.Environment.VERSION);
running it gives:
09:31:27,923 INFO [EspUser] hibernate version :: 3.3.1.GA
2) i removed
hibernate-annotations.jar hibernate-commons-annotations.jar hibernate-core.jar (3.3.1) hibernate-entitymanager.jar hibernate-jpa-2.0-api-1.0.0.Final.jar
from my buildpath and lib directory. the lib directory in my project holds all the jars my project needs to reference, but are currently included with jboss.
3) I added
hibernate-commons-annotations-4.0.1.Final.jar hibernate-core-4.1.0.Final.jar hibernate-entitymanager-4.1.0.Final.jar hibernate-jpa-2.0-api-1.0.1.Final.jarto war/web-inf/lib & to my buildpath
4) I added a new file, war/web-inf/jboss-classloading.xml. here are the contents:
<?xml version="1.0" encoding="UTF-8"?>
<classloading xmlns="urn:jboss:classloading:1.0"
export-all="NON_EMPTY"
import-all="true"
parent-first="false">
</classloading>
5) the old code at step 1) needs to be updated to: log.info("hibernate version :: " + org.hibernate.Version.getVersionString()); since hibernates api between 3 and 4 apparently changed
6) stop and restart jboss completetly and then run - the code now gives:
12:14:54,658 INFO [EspUser] hibernate version :: 4.1.0.Final
7) victory!
under:
java