ClassCastException SAXParserFactory cannot be cast to javax.xml.parsers.SAXParserFactory - jboss

I am trying to deploy an ear on Wildfly that was deployed on Websphere which has some sax parser dependencies. When I employ xml-apis-2.0.2.jar I get this error:
java.lang.ClassCastException: __redirected.__SAXParserFactory cannot be cast to javax.xml.parsers.SAXParserFactory
On the other hand, when I employ xercesImpl-2.11.0.SP4.jar, I get this error:
NoClassDefFoundError: org/xml/sax/helpers/DefaultHandler
What should I do to remove this error?

Related

how to avoid loading org.eclipse.persistence.jpa.PersistenceProvider in weblogic 14.1.1.0 version

i am using #Valid annotation at MO level to validate the input data, while it works fine with tomcat server, but during weblogic deployment i am getting below error:
Caused by: java.lang.ClassCastException: class org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to class javax.persistence.spi.PersistenceProvider (org.eclipse.persistence.jpa.PersistenceProvider is in unnamed module of loader com.oracle.classloader.weblogic.LaunchClassLoader #3e92efc3; javax.persistence.spi.PersistenceProvider is in unnamed module of loader weblogic.utils.classloaders.ChangeAwareClassLoader #8ae852)
i have tried providing <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> in my persistence as before i was using default persistence unit but still the same problem.
I want to avoid loading of persistence unit from eclipselink.jar which is present at weblogic container, so that it would not get evaluated at the end.
Any help in this would be appreciated.
Hibernate JPA Version: hibernate-jpa-2.1-api-1.0.0.Final.jar:1.0.0.Final
Hibernate Validator version: hibernate-validator-5.4.0.Final.jar:5.4.0.Final
in our case for use #Valid we deleted the lines below in weblogic.xml:
<wls:package-name>javax.persistence.*</wls:package-name>
<wls:package-name>javax.persistence.spi.*</wls:package-name>

Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

I've a gradle project which uses hibernate > 4 . If I run my war file in Apache tomcat, I don't get any error. But when I'm deploying it in Wildfly 8.2 , I get the following exception
Caused by: org.hibernate.InvalidMappingException: Error while parsing file: /G:/wildfly-8.2.0.Final/bin/content/mywar-1.0.war/WEB-INF/classes/com/mysite/
hbm/Role.hbm.xml
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1182) [hibernate-ent
itymanager-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:848) [hibernate-entitymanager-4.3.7.Fi
nal.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) [hibernate-entitymanager-4.3.7.Fi
nal.jar:4.3.7.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.7.Final.jar:4.
3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) [hibernate-entitymanager-4.3.7.Final.
jar:4.3.7.Final]
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
... 8 more
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:518) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:514) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:688) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:726) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1177) [hibernate-ent
itymanager-4.3.7.Final.jar:4.3.7.Final]
... 14 more
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot
be cast to org.dom4j.DocumentFactory
at org.dom4j.io.SAXReader.read(SAXReader.java:484) [dom4j-1.6.1.jar:1.6.1]
I just added a exclude in my Gradle file like
runtime.exclude group: "dom4j"
Now when I run gradle build, dom4j.jar is not created in the war file. Now I can run my deploy and run my project successfully on Wildfly 8.2 without any error. But the real problem starts here.
One of the feature in my project is that, it'll copy a file.xlsm to anotherfile.xlsm where I'm using jars like Apache Poi for those purposes. Here, Apache Poi is trying to access a method in dom4j.jar during file processing, it results in the following error
18:40:13,261 ERROR [io.undertow.request] (default task-29) UT005023: Exception handling request to /app/parentPath/myAction: org.springframework.web.util.NestedSe
rvletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1287) [spring-webmvc-4.1.4.RELEASE.jar:4.1.4
.RELEASE]
Any ideas how I can permanently use dom4j.jar inside my classpath? I've searched for many question and most of them suggested to remove dom4j from classpath. I do successfully run my program by removing it from classpath but it results in the above error during excel file processing. Wasted more than a day on this..!! IS it possible to include dom4j.jar in my classpath?
Update:
I've done a little trick in MANIFEST.MF file.
I've opened
mywar.war > META-INF > MANIFEST.MF
and added
Dependencies: org.dom4j export
at the end of the file and saved it. So if I deploy my war file, I'm successfully running it without any error.
Can someone explain where I've to add this kind of property in my src/ file so that it will be automatcially added to MANIFEST.MF after gradle build..
This exception on wildfly usually occurs when you include a hibernate lib in your war that's different from the wildfly one, since you are deploying to wildfly it already include hibernate so you can set you live as provided in gradle aka compileProvided and deploy without exporting the dependence.
If you still got the same error try declaring the hibernate dependency on manifest but keep the lib as provided it should work fine.
I had this same problem and i know how frustrating this one can be. I was able to resolve this problem. see my answer here. Hope this help

Liferay with struts spring hibernate

I am using Liferay 6.2.0 and creating a portlet with Struts2 + spring 3.5 and hibernate 3 framework
Nothing to worry for me.
But whenever I deploy my portlet in Liferay at that time Following error occurs.. Its not harmful for me. My portlet working what I like.
But I want to remove following error:
11:51:39,745 ERROR [http-bio-8080-exec-12][GZipFilter:81]
java.lang.ClassCastException: java.math.BigInteger cannot be cast to
java.lang.String java.lang.ClassCastException: java.math.BigInteger
cannot be cast to java.lang.String at
com.liferay.portal.servlet.BrowserSnifferImpl.getUserAgent(BrowserSnifferImpl.java:357)
...............
11:51:39,745 ERROR [http-bio-8080-exec-21][GZipFilter:81]
java.lang.ClassCastException: java.math.BigInteger cannot be cast to
java.lang.String java.lang.ClassCastException: java.math.BigInteger
cannot be cast to java.lang.String at
com.liferay.portal.servlet.BrowserSnifferImpl.getUserAgent(BrowserSnifferImpl.java:357)
at
com.liferay.portal.servlet.BrowserSnifferImpl.isMozilla(BrowserSnifferImpl.java:216)
at
com.liferay.portal.servlet.BrowserSnifferImpl.isFirefox(BrowserSnifferImpl.java:140)
Why This Error Occured ????

Spring-data-neo4j and compatibility with Scala

I suspect that Spring-data-neo4j 2.1.0-BUILD-SNAPSHOT isn't really compatible with some versions of Scala.
I use scala 2.10.0 and using a Play! web application based on scala 2.10.0 too.
While running a test involving a Neo4jTemplate autowired by Spring, I obtain this error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'mappingInfrastructure' defined in class
org.springframework.data.neo4j.config.Neo4jConfiguration: Invocation of init method failed;
nested exception is java.lang.NoSuchMethodError:
scala.collection.JavaConverters$.mapAsScalaMapConverter(Ljava/util/Map;)Lscala/collection/JavaConverters$AsScala
Does a fix exist or would be scheduled?

java.lang.NoSuchMethodError: org.apache.log4j.Logger.isTraceEnabled()

I am getting this error java.lang.NoSuchMethodError: org.apache.log4j.Logger.isTraceEnabled()
at the runtime in eclipse. However, eclipse shows the method on doing intelligence search, but at runtime it fails to identify it.
I am using the latest log4j1.2.16 jar and it is added in the classpath.
Any suggestions?