Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  CPLEX 12.9 and java

    Posted Thu July 18, 2019 11:13 AM

    Originally posted by: healyp


    Hello,

    I recently upgraded to CPLEX 12.9 under the Academic Initiative.  I can run the oplide and I can access the libraries via julia but when I try it from a java program it fails because all of the Ilog java class files are back on an earlier CPLEX release.  Can anybody tell me what I need to do to get the latest java class files, e.g. IloCplex.class, to name but one?

     

    Many thanks.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CPLEX 12.9 and java

    Posted Thu July 18, 2019 02:43 PM

    I'm not sure why you would need CPLEX class files at all. When I compile Java programs (using the NetBeans IDE, but that should not be a factor in the answer), I provide the IDE/compiler with pointers to cplex.jar (used in compilation) and CPLEX executable libraries. On a Linux system (x86 architecture), assuming the top level directory for CPLEX Studio is "xxx", the locations of those are xxx/cplex/lib/cplex.jar and xxx/cplex/lib/x86-64_linux/static_pic/ (which contains three files with names beginning with "lib" and with ".a" extensions). On Windows and MacOS, the directory locations and possibly the file extensions will change, but the concept should be the same. The compiler will produce .class files for your classes (but not for CPLEX classes). The role of CPLEX class files is subsumed by the binary library files (those with .a extensions on Linux).

    To execute a compiled program, you run "java -Djava.library.path=xxx/cplex/bin/x86-64_linux -jar <your file>.jar" (substituting the path to the binaries as described above), or else set that path in your operating system's version of a command environment (for Linux, you would export it as part of the LD_LIBRARY_PATH environment variable).

    Paul


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CPLEX 12.9 and java

    Posted Fri July 19, 2019 09:38 AM

    Originally posted by: healyp


    Thanks for your help.  I am not a java programmer and was just given this code and include files "as is."  I did not know about 'cplex.jar' and had been compiling against the cplex .class files in a subdirectory that were needed by the 'import' statements.  Following your lead I managed to compile against 'cplex.jar' with

    $ javac -Xlint -cp ".:$HOME/src/ibm-cplex/cplex/lib/cplex.jar" model.java 
    However, when I try to run this with your suggestion:

    $ java -Djava.library.path=$HOME/src/ibm-cplex/cplex/bin/x86-64_linux model

    I get

    Error: Unable to initialize main class model
    Caused by: java.lang.NoClassDefFoundError: ilog/concert/IloNumExpr

     

    There is a libconcert.a file in a concert/lib subdir of the cplex distribution but I don't know if it is useful.

    Any advice appreciated although I do not mean to turn this into a java tutorial.

     

    Thanks.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CPLEX 12.9 and java

    Posted Fri July 19, 2019 11:02 AM

    You need the classpath argument '-cp ...' for the 'java' program as well. Try something like

    $ java -Djava.library.path=$HOME/src/ibm-cplex/cplex/bin/x86-64_linux -cp ".:$HOME/src/ibm-cplex/cplex/lib/cplex.jar" model

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: CPLEX 12.9 and java

    Posted Mon July 22, 2019 04:40 AM

    Originally posted by: healyp


    Thanks, this did the job.  Thanks to Paul earlier for his assistance, too.

     

    Adding "$HOME/src/ibm-cplex/cplex/lib/cplex.jar" to my CLASSPATH environment variable allows me to tidy both compilation and run statements into:

    $ javac model.java

    $ java model


    #CPLEXOptimizers
    #DecisionOptimization