IncompatibleClassChangeError while deploying to eclipse tomcat 9 - java

I am trying to build a RESTfull service for excel type file download service. But when I try to deploy it to tomcat 9. I am getting the error of IncompatibleClassChangeError
The stacktrace is as followed : -
SEVERE: StandardWrapper.Throwable
java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2267)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:803)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1244)
And my pom.xml is
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
I was able to deploy sucessfully until I added apache.poi dependency.
What might be wrong, as I read some where to increase tomcat size to 1Gb, but it did not help.Please help someone, Thanks in advance.

Do you have two versions of the same library in your tomcat server?
What causes java.lang.IncompatibleClassChangeError?
As there says, Recompile the client code against the new library, and you should be good to go.

Related

Apache POI and Weblogic JAR conflict- POI 5 and xmlbeans

I'm currently trying to use apache POI to make excel files in java, SXSSF to be exact. When running it however, I'm getting the following error:
Caused By: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl.build(SchemaTypeLoaderImpl.java:161)
at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:198)
at org.apache.xmlbeans.metadata.system.sXMLSCHEMA.TypeSystemHolder.<init>(TypeSystemHolder.java:9)
Truncated. see log file for complete stacktrace
Caused By: org.apache.xmlbeans.XmlRuntimeException: java.lang.ClassCastException: org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl cannot be cast to org.apache.xmlbeans.SchemaTypeLoader
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl.build(SchemaTypeLoaderImpl.java:164)
at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:198)
at org.apache.xmlbeans.metadata.system.sXMLTOOLS.TypeSystemHolder.<init>(TypeSystemHolder.java:9)
at org.apache.xmlbeans.metadata.system.sXMLTOOLS.TypeSystemHolder.<clinit>(TypeSystemHolder.java:6)
at java.lang.Class.forName0(Native Method)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassCastException: org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl cannot be cast to org.apache.xmlbeans.SchemaTypeLoader
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl.build(SchemaTypeLoaderImpl.java:162)
at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:198)
at org.apache.xmlbeans.metadata.system.sXMLTOOLS.TypeSystemHolder.<init>(TypeSystemHolder.java:9)
at org.apache.xmlbeans.metadata.system.sXMLTOOLS.TypeSystemHolder.<clinit>(TypeSystemHolder.java:6)
at java.lang.Class.forName0(Native Method)
Truncated. see log file for complete stacktrace
Now, I know the similar issues to this have come up, and the usual fix is to alter weblogic.xml, and make
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.apache.commons.collections4.*</wls:package-name>
<wls:package-name>org.apache.commons.compress.*</wls:package-name>
<wls:package-name>org.apache.poi.*</wls:package-name>
<wls:package-name>org.apache.xmlbeans.*</wls:package-name>
<wls:package-name>org.apache.xmlbeans.XmlOptions</wls:package-name>
<wls:package-name>org.openxmlformats.*</wls:package-name>
<wls:package-name>schemaorg_apache_xmlbeans.*</wls:package-name>
</wls:prefer-application-packages>
<wls:prefer-application-resources>
<wls:resource-name>schemaorg_apache_xmlbeans/system/sXMLCONFIG/TypeSystemHolder.class</wls:resource-name>
<wls:resource-name>schemaorg_apache_xmlbeans/system/sXMLLANG/TypeSystemHolder.class</wls:resource-name>
<wls:resource-name>schemaorg_apache_xmlbeans/system/sXMLSCHEMA/TypeSystemHolder.class</wls:resource-name>
<wls:resource-name>schemaorg_apache_xmlbeans/system/sXMLTOOLS/TypeSystemHolder.class</wls:resource-name>
</wls:prefer-application-resources>
</wls:container-descriptor>
However, the issue arises that setting prefer-web-inf-classes to false breaks some of the rest of the application. So my question becomes, is there a way in the file I'm creating the excel, to specify that I want it to be built from the apache xmlbeans and not the weblogic xmlbeans? I'm thinking something like Classloader/Urlloader but I haven't been able to make that work properly yet, but I may be implementing it wrong.
Lastly, I'll include my pom.xml file
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${org.apache.poi-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.16.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${org.apache.commons-commons-codec-version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${org.apache.commons-commons-lang3-version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>${org.eclipse.persistence-core-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.14</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
</project>
To be more specific, in my case I had added the following code to weblogic-application.xml for fixing the exception - java.lang.ClassCastException: org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl cannot be cast to org.apache.xmlbeans.SchemaTypeLoader
<weblogic-application>
<prefer-application-packages>
<package-name>org.apache.*</package-name>
<package-name>schemaorg_apache_xmlbeans.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>schemaorg_apache_xmlbeans/*</resource-name>
</prefer-application-resources>
</weblogic-application>

cucumber.runtime.CucumberException: No backends were found

I am trying to run a BDD test with cucumber in a Maven project.
When I try to run BDDdemo.feature , I get the following error
Exception in thread "main" cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
at cucumber.runtime.Runtime.<init>(Runtime.java:81)
at cucumber.runtime.Runtime.<init>(Runtime.java:70)
at cucumber.runtime.Runtime.<init>(Runtime.java:66)
at cucumber.api.cli.Main.run(Main.java:35)
at cucumber.api.cli.Main.main(Main.java:18)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Environments
openjdk version : 13.0.1
Apache Maven : 3.6.3
TestNG : 6.14.3
cucumber : 1.2.6
IDE : IntelJ IDEA
dependencies
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.6</version>
<!--<type>pom</type>-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.6</version>
<!--<type>pom</type>-->
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.6</version>
<!--<type>pom</type>-->
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>5.3.0</version>
</dependency>
I have tried the all solutions in stack overflow regarding this issue. But nothing worked for me.
Can anyone help me with this ?
I'm assuming that, according to your pom.xml snippet, you are using TestNG and Junit. Thus, you need to add both cucumber-testng (it's already there) and cucumber-junit (it's missing) as cucumber backends. Please consider adding this other dependency entry to dependencies section on your pom.xml:
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.6</version>
</dependency>
PS: all the dependencies you listed seems to be test-scoped, so, consider add <scope>tests</scope> to each one of them to avoid unnecessarily adding those libraries to your final package (in case you are packaging a JAR).

Spring Boot - NoClassDefFoundError: javax/servlet/Filter && Unable to start ServletWebServerApplicationContext when trying to use Netty

I'm trying to use Netty server. So I excluded Tomcat in the pom.ml file;
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
When I run the application, I'm getting the error Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter
Then I add the dependency
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>compile</scope>
</dependency>
Then again when I run the application, I'm getting the error
org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
I've checked several questions and no luck yet.
Any ideas?
Enviroment
Boot: 2.1.3.RELEASE
Eclipse: 4.7
If you want to use the netty server in WebFlux and WebFlux (spring-boot-starter-webflux) use by default netty server and spring-boot-starter-web use by default tomcat server.
WebFlux provides a choice of servers (Netty, Tomcat, Jetty, Undertow, and Servlet 3.1+ containers). Both Tomcat and Jetty are servlet based servers but Netty and Undertow are non-servlet based servers.
If you want to use netty server and external jar in which using servlet API then you have to add the below dependency in pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>

Wildfly10 Server giving ClassCastException on deploying EJB module

I'm trying to move from wildfly9 to wildfly 10.
My code works properly on wildfly9
But when I try to deploy my ejb module on wildfly 10 I get the following error:
java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
I tried all the options available out there to correct this error but nothing helped me.
Here are the dependencies that i have in my pom
<dependencies>
<dependency>
<groupId>za.co.ecommunicate</groupId>
<artifactId>pl4sms-billing</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- ehcache dependency -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
<!-- ehcache dependency -->
<dependency>
<groupId>za.co.ecommunicate</groupId>
<artifactId>pl4sms-persistence</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- dependencies require for test asserts -->
<!-- <dependency> <groupId>za.co.ecommunicate</groupId> <artifactId>pl4sms-web</artifactId>
<version>1.0-SNAPSHOT</version> </dependency> -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.13</version>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>tomee-embedded</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
According to the solutions available I have found the the problem is related to hibernate, I have updated hibernate dependencies, changing the scope and also adding dom4j dependency but nothing worked.
The same module gets deployed without any problem on wildfly 9.
Can anybody help me out in resolving this error.
I have found the solution of my question may be it will help others.
i got the solution from this blog.
I added the line in my war's MANIFEST.MF file:
Open {your war}/META-INF/MANIFEST.MF
Add this line at the end - Dependencies: org.dom4j export
and added the following line in persistence.xml:
<property name="hibernate.listeners.envers.autoRegister" value="false"/ >
And it worked for me.
You problem is this:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
It brings in the old dom4j jar: Reference this ticket: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory.
You either need to remove it, declare it as provided in scope, or not run the application on the Wildfly Server (which is probably not your preferred option).

Apache Directory

I am using this doc.
But pom.xml is bit changed (because dependencies from example is not resolved and i have maven error messages), so part of pom.xml i next:
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-core</artifactId>
<version>2.0.0-M15</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-integ</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.directory.client.ldap</groupId>
<artifactId>ldap-client-api</artifactId>
<version>0.1</version>
</dependency>
Then I am running test from example i am receiving such error:
Exception in thread "main" java.lang.IncompatibleClassChangeError: Class org.apache.directory.server.core.DefaultDirectoryService does not implement the requested interface org.apache.directory.server.core.DirectoryService
at org.apache.directory.server.core.integ.FrameworkRunner.run(FrameworkRunner.java:170)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
Any ideas?
Test Class: http://pastebin.com/aPisMRSx
Change the version of apacheds-all to the same version as apacheds-core

Categories