0

I'm trying to compile/build/run a Java project for the first time on Ubuntu 14.04. The project depends on the CPlex optimization library. I've compiled the code using

javac -classpath .:/opt/ibm/ILOG/CPLEX_Studio_Community128/cplex/lib/cplex.jar ./bendersexample/*.java

Then I created a Manifest file, MANIFEST.MF, which looks like this:

Manifest-Version: 1.0
Main-Class: bendersexample.Demo

And then I created the .jar like so:

jar -cfm example.jar MANIFEST.MF ./bendersexample/*.class

I want to execute my code by running this:

java -Djava.library.path=/opt/ibm/ILOG/CPLEX_Studio_Community128/cplex/bin  -jar example.jar

However, I get the following error:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: ilog/concert/IloException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: ilog.concert.IloException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

Actually, I get the exact same error when I just run

java -jar example.jar

So I think that the problem has something to do with Java not being able to find the library? I'm 100% sure that the path given is where CPlex was installed.

java -version returns

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

and javac -version returns

javac 1.8.0_161

1 Answer 1

0

I took a look at the contents of the .jar file and the Main class was listed as bendersexample.Demo. I was creating and running the jar in the /bendersexample directory.

The solution for me was simply to move the Manifest and jar file to the parent directory.

Anyone who has a problem like this in the future should take a look at their project file structure before trying anything else because this turned out to be a very easy fix!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .