4 Installation

In this section we discuss how to install and setup the MOSEK Optimizer API for Java.

Important

Before running this MOSEK interface please make sure that you:

  • Installed MOSEK correctly. Some operating systems require extra steps. See the Installation guide for instructions and common troubleshooting tips.

  • Set up a license. See the Licensing guide for instructions.

Compatibility

The Optimizer API for Java is compatible with Java version 1.8 or later on 64bit platforms (Linux, Windows, macOS).

Locating files in the MOSEK Optimization Suite

The relevant files of the Optimizer API for Java are organized as reported in Table 4.1.

Table 4.1 Relevant files for the Optimizer API for Java.

Relative Path

Description

Label

<MSKHOME>/mosek/11.0/tools/platform/<PLATFORM>/bin

Libraries and jar file

<JARDIR>

<MSKHOME>/mosek/11.0/tools/examples/java

Examples

<EXDIR>

<MSKHOME>/mosek/11.0/tools/examples/data

Additional data

<MISCDIR>

where

  • <MSKHOME> is the folder in which the MOSEK Optimization Suite has been installed,

  • <PLATFORM> is the actual platform among those supported by MOSEK, i.e. win64x86, linux64x86, linuxaarch64 or osxaarch64.

Setting up paths

To compile and run a Java program using MOSEK the correct path to the JAR file

<JARDIR>/mosek.jar

must be provided in the Java classpath. This is usually set with the command line option -classpath, or the environment variable CLASSPATH, or any other method that your Java environment/compiler supports. For more information about specifying class libraries and compiling applications, see the full Java documentation at http://java.sun.com/.

4.1 Building Examples and Testing the Installation

This section describes how to verify that MOSEK has been installed correctly, and how to build and execute the Java examples distributed with MOSEK.

4.1.1 Windows

Building and executing a program

To compile the example lo1.java distributed with MOSEK:

  • Open a DOS prompt and go to the examples directory <EXDIR>.

  • To compile a Java program and produce the class files in the current directory, type

    javac -classpath <JARDIR>\mosek.jar -d . lo1.java
    
  • To run the compiled program, type

    java -classpath .:<JARDIR>\mosek.jar com.mosek.example.lo1       (Linux/OSX)
    java -classpath .;<JARDIR>\mosek.jar com.mosek.example.lo1       (Windows)
    

Compiling with Microsoft NMake

The distributed examples can also be compiled using Microsoft NMake. This requires that paths and environment is set up for Visual Studio tools (usually, the sub-menu containing Visual Studio also contains a Visual Studio Command Prompt which take care of all the necessary setup).

To build the examples, open a DOS box and change directory to the examples directory <EXDIR>. To compile all examples type

nmake /f Makefile

This will compile all the classes into a jar file. To run all the examples type

nmake /f Makefile test

4.1.2 macOS and Linux

Building and executing a program

To compile the example lo1.java distributed with MOSEK:

  • Open a console and go to the examples directory <EXDIR>.

  • To compile a Java program and produce the class files in the current directory, type

    javac -classpath <JARDIR>/mosek.jar -d . lo1.java
    
  • To run the compiled program, type

    java -classpath .:<JARDIR>/mosek.jar com.mosek.example.lo1
    

Compiling examples using make

The example directory contains makefiles for use with GNU Make. To build the examples, open a prompt and change directory to the examples directory <EXDIR>. To compile all examples type

make -f Makefile

This will compile all the classes into a jar file. To run all the examples type

make test