0

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)
rkersh
  • 4,447
  • 2
  • 22
  • 31
Aurelien
  • 67
  • 5
  • Can you post the full backtrace of the error? From what you showed there is no proof that this indeed comes from cplex or using cplex. Can you clean your project and build again and make sure the correct cplex.jar is used? Maybe you had an outdated cplex.jar somewhere on your system and were building with that. – Daniel Junglas May 28 '19 at 12:00
  • Have you tried running a maven clean after adding the library? – Guillaume May 28 '19 at 12:17
  • Building with OPL requires you to build with `oplall.jar` on the class path. That is incompatible with `cplex.jar`. You can only use one of the two at a time. Do things work any better if you remove `cplex.jar` from the classpath/dependencies? Actually, did you register `oplall.jar` with maven as well? – Daniel Junglas May 28 '19 at 14:02
  • @DanielJunglas I replace all cplex import by oplall and it's working. Please write it as a response and not as commentary so I can accept it. – Aurelien May 28 '19 at 14:44

1 Answers1

1

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.

Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22