Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

How to setup cplex when using Java with eclipse?

  • 1.  How to setup cplex when using Java with eclipse?

    Posted Wed May 19, 2010 03:45 PM

    Originally posted by: Grace360


    Question:

    Dear support,
    I have installed IBM ILOG license key correctly,but I can not run the program (write by java in eclipse )using CPLEX in this computer with CPLEX correctly installed in it . These programs work well in another computer with different cplex version. Can you please tell me why does this happen and how to solver such problems?
    Here is the error message :

    java.lang.UnsatisfiedLinkError: no cplex121 in java.library.path
    java.library.path must point to the directory containing the CPLEX shared library
    try invoking java with java -Djava.library.path=...
    Exception in thread "main" java.lang.UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J
    at ilog.cplex.Cplex.CPXopenCPLEX(Native Method)
    at ilog.cplex.CplexI.init(CplexI.java:5358)
    at ilog.cplex.CplexI.<init>(CplexI.java:525)
    at ilog.cplex.IloCplex.<init>(IloCplex.java:9229)
    at AgusPractice.DietPractice.main(DietPractice.java:128)

    Thank you very much

    Grace
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to setup cplex when using Java with eclipse?

    Posted Wed May 19, 2010 04:42 PM

    Originally posted by: SystemAdmin


    Is this occurring inside Eclipse or when you try to run the compiled code (.class or .jar file) outside CPLEX? If it occurs inside CPLEX, you need to add the location of the CPLEX executable to your library entry for Eclipse (Window > Preferences > Java > Build Path > User Libraries). Click the arrow next to cplex.jar to expand it, select Native library location, and set it to point to the folder (should be under .../bin) that contains the CPLEX library (.so extension on Linux, .dll on Windows).

    If the problem occurs when running the compiled code, add the same path to the library path option in the command line (-Djava.library.path=...).

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to setup cplex when using Java with eclipse?

    Posted Wed May 19, 2010 06:16 PM

    Originally posted by: Grace360


    Hi,Paul,

    Thank you very much.

    Grace
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Comment installer CPLEX pour l'utilisation de Java avec Eclipse?

    Posted Tue April 15, 2014 04:39 AM

    Originally posted by: MAYMA


    Dear support, I have installed cplex.jar correctly, i introduced it in my application which developed by java in netbeans, the programs work well, but i can't resolve the problem, when i run the compiled code, i get this message: 

    ‹Exception in thread "main" java.lang.UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J

    at ilog.cplex.Cplex.CPXopenCPLEX(Native Method)
    at ilog.cplex.CplexI.init(CplexI.java:5358)
    at ilog.cplex.CplexI.<init>(CplexI.java:525)
    at ilog.cplex.IloCplex.<init>(IloCplex.java:9229)
    at ACVRP_without_y.main(ACVRP_without_y.java:317)
    java.lang.UnsatisfiedLinkError: no cplex121 in java.library.path
    java.library.path must point to the directory containing the CPLEX shared library
    try invoking java with java -Djava.library.path=...

    i read your answer that you say 'If the problem occurs when running the compiled code, add the same path to the library path option in the command line (-Djava.library.path=...).  ' but i don't understand how i could do that and where i found the command line

    thank you 


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Comment installer CPLEX pour l'utilisation de Java avec Eclipse?

    Posted Tue April 15, 2014 04:48 AM

    You have to start the JVM with argument -Djava.library.path=/path/to/lib where /path/to/lib is the absolute path to the folder that contains libcplex121.so/libcplex121.dll (depending on your platform).

    I don't know netbeans so I don't know how to do that in netbeans, but this seems to explain how to do that.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: How to setup cplex when using Java with eclipse?

    Posted Sat April 22, 2017 08:51 PM

    Originally posted by: ZJay


    Hi there, I run a jar file on tomcat and facing the same issue. Could you explain more about how to "add the same path to the library path option in the command line (-Djava.library.path=...)"

    Appreciate you clarification
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: How to setup cplex when using Java with eclipse?

    Posted Tue April 25, 2017 03:47 AM

    This is standard java configuration. You have to invoke the JVM to with -Djava.library.path=/path/to/libs where /path/to/libs is the folder that contains the shared object files like libcplexVERSION.so (VERSION is the CPLEX version number). This folder is located somewhere under the cplex/bin folder in your installation. The exact place depends on your platform.

    Another way to fix this is to add /path/to/libs to the LD_LIBRARY_PATH environment variable before starting the JVM (or tomcat in your case, I guess).


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: How to setup cplex when using Java with eclipse?

    Posted Mon June 20, 2016 10:24 AM

    Originally posted by: Steamera


    Hello,

     

    
    I have a similar problem for a grails application running on a tomcat server.
    The application was developed under windows on the IDE IntelliJ Idea.
    
    The cplex.jar is in the libraries folder 
    
    I inserted in the VM options (my "libcplex1260.so" file is in this folder)
    :
    
    -Djava.library.path=/opt/ibm/ILOG/CPLEX_Studio126/cplex/bin/x86-64_linux/ 
    
    But I got the error :
    
    

     

    .

    Caused by UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J
    ->> 6594 | init      in ilog.cplex.CplexI
    
    
    CPLEX is installed on the Windows PC and on the PC linux (with tomcat) .
    The application works well on windows when I execut it with IntelliJ Idea but on linux 
    with the exported application I have the error. 
    
    On the linux pc I tested CPLEX from the command line by running the Java CPLEX tests
     as explained on the IBM website. CPLEX works well.
    I do not understand where the problem is.
    
    How to solve UnsatisfiedLinkError message ?
    

    bests regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: How to setup cplex when using Java with eclipse?

    Posted Mon June 20, 2016 10:52 AM

    Is this the only error you see? Do you see any errors before? Like errors that would suggest that the .so could not be loaded or found. Are you by any chance mixing a 32bit Java virtual machine with 64bit CPLEX library?


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: How to setup cplex when using Java with eclipse?

    Posted Tue June 21, 2016 03:03 AM

    Originally posted by: Steamera


    
    Hello
    
    Thank you for this quick response.
    
    Here is the full error message
    
        Line | Method
    ->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    745 | run . . . in java.lang.Thread
    
    Caused by ControllerExecutionException: Runtime error executing action
    ->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    745 | run . . . in java.lang.Thread
    
    Caused by InvocationTargetException: null
    ->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    745 | run . . . in java.lang.Thread
    
    Caused by UnsatisfiedLinkError: ilog.cplex.Cplex.CPXopenCPLEX([I)J
    ->> 6594 | init      in ilog.cplex.CplexI
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |    629 | <init>    in     ''
    |   11067 | <init> .  in ilog.cplex.IloCplex
    |   11082 | <init>    in     ''
    |     94 | save . .  in agriplan.APProjectController
    |   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    745 | run       in java.lang.Thread
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: How to setup cplex when using Java with eclipse?

    Posted Tue June 21, 2016 03:21 AM

    I am wondering whether you don't see any other output from CPLEX before that error. For example, if CPLEX cannot load the native library it should print something like this to stdout:

    <exception message here>
    java.library.path must point to the directory containing the CPLEX shared library
    try invoking java with java -Djava.library.path=...

    Do you see this anywhere? Or do you swallow/redirect messages on stdout somehow?

    Can you try if the problem persists if you set environment LD_LIBRARY_PATH=/opt/ibm/ILOG/CPLEX_Studio126/cplex/bin/x86-64_linux before starting your application? Also, can you print System.getProperty("java.library.path") and System.getenv("LD_LIBRARY_PATH") from your application to make sure the settings actually make it to your app?


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: How to setup cplex when using Java with eclipse?

    Posted Thu June 23, 2016 05:06 AM

    Originally posted by: Steamera


    Thank you Daniel It works !

    
    You were right, it was a problem with LD_LIBRARY_PATH
    So I made a symbolic link to the libcplex1260.so in the /usr/lib folder
    
    cd /usr/lib
    ln -s /opt/ibm/ILOG/CPLEX_Studio126/cplex/bin/x86-64_linux/libcplex1260.so .
    
    Thank you again
    
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: How to setup cplex when using Java with eclipse?

    Posted Thu June 23, 2016 06:15 AM

    Well, if this works then something was wrong with your java.library.path before. Either it pointed to the wrong place or its value did not properly propagate to the context in which the CPLEX classes are loaded.


    #CPLEXOptimizers
    #DecisionOptimization