Search code examples
javamavencplexopl

How to fix 'IncompatibleClassChangeError: Implementing Class' when importing Cplex library in Maven project?


I'm trying to import Cplex on a Maven project (using Ubuntu 16.04).

So I added cplex.jar to maven repository with this command : mvn install:install-file -DgroupId=cplex -DartifactId=cplex -Dversion=12.8 -Dpackaging=jar -Dfile=/cplex/install/dir/CPLEX_Studio128/cplex/lib/cplex.jar

I added the dependency to my pom.xml :

<dependency>
    <groupId>cplex</groupId>
    <artifactId>cplex</artifactId>
    <version>12.8</version>
</dependency>

I added the link of the Cplex Native Library (.so files) to the LD_LIBRARY_PATH : export LD_LIBRARY_PATH="/cplex/install/dir/CPLEX_Studio128/cplex/bin/x86-64_linux"

But when I'm running my maven project with : mvn exec:java -Dexec.mainClass="main.main"

I got the following error : java.lang.IncompatibleClassChangeError: Implementing Class

I have already checked this question but I don't understand, in this case, what kind of incompatibles binary changes can be made.

Is it possible that there's some "incompatibles binary changes" ? And if it's not, is there any other explanation than an "incompatibles binary changes" to this error ?

Edit

I also use OPL library (same installation than Cplex library) and I have only the 12.8 version of Cplex and Oplall on my system.

I tried to clean and build again but got the same error.

This is the code I try to run (in ModelFileEvaluator.java) :

IloOplFactory.setDebugMode(true);
IloOplFactory oplF = new IloOplFactory();
IloOplErrorHandler errHandler = oplF.createOplErrorHandler();
IloOplModelSource modelSource = oplF.createOplModelSource(fileName);
IloOplSettings settings = oplF.createOplSettings(errHandler);
IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource,settings);
IloCplex cplex = oplF.createCplex();

And this is the full backtrace :

java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(java.base@9-internal/Native Method)
    at java.lang.ClassLoader.defineClass(java.base@9-internal/ClassLoader.java:939)
    at java.security.SecureClassLoader.defineClass(java.base@9-internal/SecureClassLoader.java:152)
    at java.net.URLClassLoader.defineClass(java.base@9-internal/URLClassLoader.java:463)
    at java.net.URLClassLoader.access$100(java.base@9-internal/URLClassLoader.java:76)
    at java.net.URLClassLoader$1.run(java.base@9-internal/URLClassLoader.java:371)
    at java.net.URLClassLoader$1.run(java.base@9-internal/URLClassLoader.java:365)
    at java.security.AccessController.doPrivileged(java.base@9-internal/Native Method)
    at java.net.URLClassLoader.findClass(java.base@9-internal/URLClassLoader.java:364)
    at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:486)
    at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:419)
    at java.lang.ClassLoader.defineClass1(java.base@9-internal/Native Method)
    at java.lang.ClassLoader.defineClass(java.base@9-internal/ClassLoader.java:939)
    at java.security.SecureClassLoader.defineClass(java.base@9-internal/SecureClassLoader.java:152)
    at java.net.URLClassLoader.defineClass(java.base@9-internal/URLClassLoader.java:463)
    at java.net.URLClassLoader.access$100(java.base@9-internal/URLClassLoader.java:76)
    at java.net.URLClassLoader$1.run(java.base@9-internal/URLClassLoader.java:371)
    at java.net.URLClassLoader$1.run(java.base@9-internal/URLClassLoader.java:365)
    at java.security.AccessController.doPrivileged(java.base@9-internal/Native Method)
    at java.net.URLClassLoader.findClass(java.base@9-internal/URLClassLoader.java:364)
    at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:486)
    at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:419)
    at ilog.opl.IloOplFactory.createCplex(IloOplFactory.java:227)
    at main.ModelFileEvaluator.testFile(ModelFileEvaluator.java:86)
    at main.ModelFileEvaluator.main(ModelFileEvaluator.java:53)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-internal/Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(java.base@9-internal/NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-internal/DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(java.base@9-internal/Method.java:531)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
    at java.lang.Thread.run(java.base@9-internal/Thread.java:804)

Solution

  • Using OPL requires using oplall.jar. That jar is not compatible with cplex.jar. You can use only one of the two at the same time. Removing cplex.jar from the class path should fix the issue.