4. Testing installation and compiling examples


This chapter describes how to compile and run the Java examples distributed with MOSEK.

To use the MOSEK Java API you must have a working installation of MOSEK. See the MOSEK Installation manual for instructions.

4.1. Microsoft Windows Platform

The MOSEK Java API consists of two files:

4.1.1. Compiling and executing a program

We will show how to compile the example lo1.java distributed with MOSEK. We assume that MOSEK is installed in the directory denoted <base>.

  1. Open a DOS prompt.
  2. Change directory to where the program source files are located, for example by typing

      C:
      cd <base>\mosek\6\tools\examples\java
    
  3. To compile a Java program, placing the class files in the current directory, type

      javac -classpath <base>\mosek\6\tools\platform\win32x86\bin\mosek.jar -d . lo1.java
    

    where <base> is the location of the MOSEK installation. By default the installer will place MOSEK in 'C:\Program Files' or a similar location, depending on the language setup. Above we assumed that we are compiling for the 32 bit version of MOSEK. For the 64 bit version win32x86 must be replace with win64x86.

  4. To run the compiled program when it has been compiled, type

      java -classpath <base>\mosek\6\tools\platform\win32x86\bin\mosek.jar;. lo1.lo1
    

If the environment variable CLASSPATH has been set to contain mosek.jar, then the part

<base>\mosek\6\tools\platform\win32x86\bin\mosek.jar

may be left out of the -classpath argument.

For more information about specifying class libraries and compiling applications, see the full Java documentation at

http://java.sun.com/

4.1.1.1. 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. For English Windows with default installation directories, this is the directory

c:\Program Files\mosek\6\tools\examples\java

The directory contains several makefiles. You should use either Makefile.win32x86 or Makefile.win64x86, depending on your installation. For 32-bit Windows type

nmake /f Makefile.win32x86 all

and similarly for 64-bit Windows, type

nmake /f Makefile.win64x86 all

To build a single example instead of all examples, replace “all” by the corresponding executable name. For example, to build lo1.exe on 32-bit Windows, type

nmake /f Makefile.win32x86 lo1.exe

4.1.2. Common problems

  • When executing a Java program I get

    java.lang.UnsatisfiedLinkError: no mosek6_0 in java.library.path
    

    The Java Virtual Machine was unable to find the dll mosekjava6_0.dll. This probably means that the path environment variable does not contain the location of the dll. See MOSEK installation manual on how to set paths correctly.

  • When executing a Java program I get a message box saying “The application failed to start because mosek6_0 was not found”.

    This means that the location of the dll mosek6_0 was not included in the PATH environment variable. See how to do this above.

  • When compiling a Java example I get “package mosek does not exist”. The Java archive mosek.jar was not included in the classpath. The classpath may be specified in three ways. It can be specified on the command line using the '-classpath' option for java and javac. For example

    javac -classpath C:\mosek\6\tools\platform\win32x86\bin\mosek.jar -d . lo1.java
    

    Alternatively, the classpath may be set as an environment variable. See how to do this above.

4.2. Linux Platform

The MOSEK Java API consists of two files:

4.2.1. Setting PATH and CLASSPATH

Before the MOSEK Java API can be used, the system environment must be set correctly up:

  • The environment variable LD_LIBRARY_PATH must contain the path to the mosek library.
  • The environment variable CLASSPATH must contain the path to mosek.jar.

You can verify that this is the case as follows: Open a shell and type

  echo $PATH

This prints a “:”-separated list of paths which should contain the path to MOSEK. Then type

  echo $CLASSPATH

This prints a “:”-separated list of paths which should contain mosek.jar. If one of the above was missing, they must be set up. This can be done either temporarily or permanently:

  • The variables can be temporarily set in current shell. In Bash this can be done by typing

      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"<base>/mosek/6/tools/platform/<arch>/bin"
      export CLASSPATH=$CLASSPATH:"<base>/mosek/6/tools/platform/<arch>/bin/mosek.jar"
    

    where <base> is the directory where MOSEK is installed and <arch> is either “linux32x86” (on 32-bit Linux) or “linux64x86” (on 64-bit linux). Note that other shells may require a different syntax.

  • The variables can be permanently set by including following lines in  /.bashrc

    if [ -z "$LD_LIBRARY_PATH" ]; then
      export LD_LIBRARY_PATH="<base>/mosek/6/tools/platform/<arch>/bin"
    else
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"<base>/mosek/6/tools/platform/<arch>/bin"
    fi
    
    if [ -z "$CLASSPATH" ]; then
      export CLASSPATH="<base>/mosek/6/tools/platform/<arch>/bin/mosek.jar"
    else
      export CLASSPATH=$CLASSPATH:"<base>/mosek/6/tools/platform/<arch>/bin/mosek.jar"
    fi
    

    where <base> is the directory where MOSEK is installed and <arch> is either “linux32x86” (on 32-bit systems), “linux64x86” (on AMD64 or EM64T) or “linuxia64” (on Itanium). Note that other shells may require a different syntax.

4.2.2. Compiling and executing a program

We will show how to compile the example lo1.java distributed with MOSEK. We assume that MOSEK is installed in the directory denoted <base>.

  1. Open a shell.
  2. Change directory to where the program source files are located, for example by typing

      cd <base>/mosek/6/tools/examples/java
    
  3. To compile a Java program, placing the class files in the current directory, type

      javac -classpath <base>/mosek/6/tools/platform/<arch>/bin/mosek.jar -d . lo1.java
    

    where <base> is the location of the MOSEK installation and <arch> is linux32x86, linux64x86 or linuxia64 depending in the machine architecture.

  4. To run the program when it has been compiled, type

      java -classpath  <base>/mosek/6/tools/platform/<arch>/bin/mosek.jar:. lo1.lo1
    

If the environment variable CLASSPATH has been set to contain mosek.jar, then the part

<base>/mosek/6/tools/platform/<arch>/bin/mosek.jar

may be left out of the -classpath argument.

For more information about specifying class libraries and compiling applications, see the full Java documentation at

http://java.sun.com/

4.2.2.1. Compiling examples using GMake

The example directory contains makefiles for use with GNU Make.

To build the examples, open a prompt and change directory to the examples directory. For Linux with default installation directories, this is the directory

mosek/6/tools/examples/java

The directory contains several makefiles. You should use either Makefile.lnx32x86 or Makefile.lnx64x86, depending on your installation. For 32-bit Linux type

gmake -f Makefile.lnx32x86 all

and similarly for 64-bit Windows, type

gmake -f Makefile.lnx64x86 all

To only build a single example instead of all examples, replace “all” by the corresponding executable name. For example, to build lo1 on 32-bit Linux, type

gmake -f Makefile.lnx64x86 lo1

4.2.3. Common problems

  • When executing a Java program I get

    java.lang.NoClassDefFoundError: mosek/XYZ
    

    where XYZ is some MOSEK Java class. The mosek.jar library was not found. Make sure that the classpath is defined either on the command line or in the environment variable CLASSPATH, and that it contains the location of mosek.jar.

  • When executing a Java program I get

    java.lang.UnsatisfiedLinkError: no mosek6_0 in java.library.path
    

    The Java Virtual Machine was unable to find the dll libmosekjava6_0.so. This probably means that the LD_LIBRARY_PATH environment variable does not contain the location of the dll. See MOSEK installation manual on how to set paths correctly.

  • When executing a Java program I get

     java.lang.UnsatisfiedLinkError:
     /home/ulfw/mosekprj/dev/examples/tools/java/libmosekjava4_0.so: ...
    

    or similar. This means that the the location of the dll libmosek.so.6.0 or some library libmosek it depends on was not included in the LD_LIBRARY_PATH environment variable. See MOSEK installation manual on how to set paths correctly.

  • When compiling a Java example I get “package mosek does not exist”.

    The Java archive mosek.jar was not included in the classpath. The classpath may be specified in three ways. It can be specified on the command line using the '-classpath' option for java and javac. For example

    javac -classpath $HOME/mosek/6/tools/platform/linux32x86/bin/mosek.jar -d . lo1.java
    

    Alternatively, the classpath may be given as an environment variable. This variable can be temporarily specified on the command line, for example in bash

    export CLASSPATH=$HOME/mosek/6/tools/platform/linux32x86/bin/mosek.jar
    

    You may add this line to a startup script (e.g. $HOME/.bashrc or $HOME/.tcshrc depending on which shell is used).

Wed Feb 29 16:00:42 2012