Setting up Eclipse for the Java API of CPLEX

Regardless of platform, you can make Eclipse aware of the Java API of CPLEX.

To make your Eclipse integrated development environment aware of the Java API of CPLEX, follow these steps.

  1. Either import an existing project, or create a new Java project.

    To import an existing Java project, first click File > Import .... When Select opens, expand the General folder. Within the General folder, select Existing Projects into Workspace.

    To create a new Java project, click File > New ... > Java Project.

  2. To include the CPLEX JAR in your project, locate the libraries among the properties of the project, like this:

    Project > Properties > Java Build Path > Libraries

  3. Click the button Add External JARs.

  4. Browse to the location of your CPLEX installation and select the file named cplex.jar.

Tip:

Be sure to point to the CPLEX JAR, cplex.jar, not simply the folder or directory containing that file. Conventionally, the CPLEX JAR is in the lib directory of your CPLEX home, part of the installation of IBM ILOG CPLEX Optimization Studio.

After that procedure, you can create and compile your source code making use of the Java API of CPLEX.

Before you can run your compiled code, you must create an appropriate run configuration in Eclipse or modify an existing run configuration appropriately. To do so, follow these steps.

  1. Create a new run configuration or locate an existing run configuration to modify, like this:

    Run > Run Configurations ... > Java Application

  2. When the dialog appears, go to the Main tab, and select your main class; that is, select the class containing the main() function that you want to run.

  3. Go to the Arguments tab, select VM arguments, and add the path to the CPLEX library. The CPLEX library is conventionally a DLL file on Windows or a .so file on UNIX or GNU/Linux, with an indication of the version number in its name, like cplexXX.dll or cplexXX.so where XX represents a version number of the product.

    Tip:

    Add the path to the directory or folder containing the CPLEX library (not the name of the file itself).

    For example, on UNIX or GNU/Linux , if the file libcplexXX.so is located in the directory COSinstallation/cplex/bin/myPlatform/myLibFormat then add a path similar to this example:

    -Djava.library.path= COSinstallation/cplex/myPlatform/myLibFormat

    Similarly, on Windows, if the file cplexXX.dll is located in the folder COSinstallation\cplex\myPlatform\myLibFormat then add a path similar to this example:

    -Djava.library.path=COSinstallation/cplex/myPlatform/myLibFormat

After these steps, you can run your Java application using CPLEX as you run other applications from Eclipse.