<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: How to stop my WAR loading JBoss's provided 3rd party classes?
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/edward_nickson">edward_nickson</a> in <i>JBoss Microcontainer</i> - <a href="https://community.jboss.org/message/730457#730457">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>I have recently gone through the painful process of deploying an application on JBOSS 5.1.0.GA that was deploying fine on JBOSS 4.2.1.GA. It took me quite a while with much searching of the internet for help. I thought I should post what I did in case it helps others solve their own migration issues. This thread seemed like the best place to post it. Please note that not all of these problems will be encountered by all users and it is possible that some of the assumptions/statements that I found on the net and used were wrong. But overall the discussions I leveraged helped me immensely. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The application contained the following major 3rd party software:</p><p>-hibernate 3.6.0.Final + JTA 2.0</p><p>-Camel 2.6.0</p><p>-Spring 3.0.5.RELEASE</p><p>-Atomikos 3.7.0</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The packaging was a WAR file.</p><p>  </p><p>Here were the final steps required to deploy it:</p><p>  </p><p>1) Set classloading:</p><p>Added jboss-classloading.xml and edited jboss-web.xml to load the WAR in its own domain and its own META-INF/lib jars before Jboss'.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>AppBuild.war/WEB-INF/jboss-classloading.xml:</p><p><?xml version="1.0" encoding="UTF-8"?></p><p><span><!-- See </span><a class="jive-link-external-small" href="http://phytodata.wordpress.com/2010/10/21/demystifying-the-jboss5-jboss-classloading-xml-file" target="_blank">http://phytodata.wordpress.com/2010/10/21/demystifying-the-jboss5-jboss-classloading-xml-file</a><span> --></span></p><p><classloading xmlns="urn:jboss:classloading:1.0"</p><p>     parent-first="false"</p><p>     domain="AppBuild"</p><p>     top-level-classloader="true"</p><p>     export-all="NON_EMPTY"</p><p>     import-all="false"></p><p></classloading></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>AppBuild.war/WEB-INF/jboss-web.xml:</p><p><?xml version="1.0" encoding="UTF-8"?></p><p><jboss-web></p><p>    <context-root>/CONTEXT_ROOT_NAME</context-root></p><p>  <class-loading java2ClassLoadingCompliance="false"></p><p>  <loader-repository>com.whatever:loader=AppBuild</p><p>  <loader-repository-config>java2ParentDelegation=false</loader-repository-config></p><p>  </loader-repository></p><p>  </class-loading></p><p></jboss-web></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Helpful URLS:</p><p><a class="jive-link-external-small" href="http://phytodata.wordpress.com/2010/10/21/demystifying-the-jboss5-jboss-classloading-xml-file/" target="_blank">http://phytodata.wordpress.com/2010/10/21/demystifying-the-jboss5-jboss-classloading-xml-file/</a></p><p><a class="jive-link-external-small" href="https://community.jboss.org/docs/DOC-13178" target="_blank">https://community.jboss.org/wiki/JBoss5CustomMetadataFiles</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>2) Prevent JBoss' older hibernate version attempting to deploy PUs:</p><p>JBoss should be using the newer hibernate 3.6.0.Final to deploy, but it will attempt to load them anyway using the older version. I thus renamed all persistence.xml's in the application so that JBoss will not detect them and pointing Spring to the new names:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Added: <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-newname.xml"/></p><p>To the Entity Manager Factory Bean: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Exception:</p><p>java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>NOTES:</p><p>JBoss is supposed to be able to filter out classes/packages from the domain. This is supposed to be done with : jboss-classloading-domain.xml. Unfortunately this classloading file causes unexpected changes that override the "parent-first=false" config specified in the classloading file. It should therefore not be used (as specified earlier in this thread)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>It should also be possible to have JBOSS ignore the persistence.xmls instead of having to rename them. Exqually unfortunate that: jboss-ignore.txt does not appear to work.</p><p><span>SOURCE=</span><a class="jive-link-external-small" href="https://community.jboss.org/message/607119#607119#607119" target="_blank">https://community.jboss.org/message/607119#607119</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>3) Remove any xml library conflicts:</p><p>Several jars within the application caused a conflict (cannot cast exceptions) even though classloading is supposed to be isolated. All of these are regarding xml parsing. I had to removed the following jars from the WAR:</p><p>-xerces</p><p>-xml-apis</p><p>-xmlParserAPIS</p><p>-stax-api</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Exception Example:</p><p>Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>4) Remove any servlet.http jars:</p><p>A couple of jars contained implementations of the javax.servlet.http. These were overriden under JBoss 4.2.1.GA but were now being loaded first. The effect was that the Spring context did not start, and a servlet context exception was thrown. I had to remove the following jars:</p><p>-geronimo-servlet_2.4_spec-1.1.1</p><p>-servlet-api-2.5.jar</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Exception:</p><p>java.lang.ClassCastException: com.xxx.xxx.xxx.Servlet cannot be cast to javax.servlet.Servlet</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>5) Correct Camel type converter loading:</p><p>A new file system was introduced in JBOSS 5 called VFS. This causes a problem with camel's type converters. The camel team are aware of this issue but there is no straightforward fix included in Camel. There is a recommended class available to fix the issue outside of Camel, but there is not even a readily available maven artifact for it (that I could find). The source code that I found was also tied directly to JBOSS 6. (JBOSS VFS classes were refactored between JBOSS 5 and 6.) I therefore modified the class myself for JBoss 5 and created the artifact. Lastly, I created a Spring bean to instantiate the class. This rectified the Camel exception. It is very unfortunate that the Camel team do not address this issue clearly on the Camel website with an easily to use maven artifact. They do indicate it is solved in newer versions of Camel but I have not had much success getting it to work without this bean for those versions thus far.  </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Exception:</p><p>Caused by: org.apache.camel.RuntimeCamelException: org.apache.camel.TypeConverterLoaderException: Failed to load type converters because of: Cannot find any type converter classes from the following packages: [org.apache.camel.component.file, org.apache.camel.component.bean, org.apache.camel.converter, org.apache.activemq.camel.converter, org.apache.camel.component.http]</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>6) Update Camel to accommodate type converter fix:</p><p>The camel type converters were able to load, however a follow up error appeared:</p><p>Caused by: java.lang.NoSuchFieldError: log</p><p>at org.apachextras.camel.jboss.JBossPackageScanClassResolver.find(JBossPackageScanClassResolver.java:24)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The camel team indicated that this error is due to a change in logging and usage of SLF4J. It requires camel 2.7.0+. I therefore upgraded to the latest 2.9.1.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>7) Disable hibernate validation or remove JBOSS' old validator.jar:</p><p>JBoss' built in legacy hibernate validator was throwing the following exception in attempting validation:</p><p>Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The sourcecode for JBoss does not permit this problem from being solved with classloading. It must either be solved by:</p><p>a-removing JBOSS_ROOT/common/lib/hibernate-validator.jar </p><p>OR</p><p>b-disabling validation</p><p><span>SOURCE URL: </span><a class="jive-link-external-small" href="https://community.jboss.org/message/553449#553449#553449#553449" target="_blank">https://community.jboss.org/message/553449#553449#553449</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I chose to disable validation by adding the following to the jpaPropertyMap of the Entity Manager Factory Bean: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean:</p><p><entry key="hibernate.validator.apply_to_ddl" value="false"/></p><p><entry key="hibernate.validator.autoregister_listeners" value="false"/></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>8) DB Driver:</p><p>The driver file previously could be included inside the WAR file. Under new JBoss this was causing an exception:</p><p>Caused by: org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: net.sourceforge.jtds.jdbc.Driver, url: ...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I therefore placed the jtds-1.2.4.jar in JBOSS_ROOT/server/default/deploy/lib </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>9) The application now deploys.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/730457#730457">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Microcontainer at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2114">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>