Visual Servoing Platform  version 3.4.0
Tutorial: Installing ViSP for Java

Introduction

At this point we suppose that you succeed to build ViSP from source following one Installation from source code tutorials.

This tutorial will help you to build ViSP from source for Java on your desktop. It shows how to proceed if your desktop is running Linux, OSX or Windows.

Create a workspace

First create a workspace in $HOME/visp-ws that will contain ViSP sources, build and dataset.

$ export VISP_WS=$HOME/visp-ws
$ mkdir -p $VISP_WS

Install Java Development Kit (JDK)

Note
At the time this tutorial was updated, the lastest Java SE Development Kit (JDK) is version 15. There is also JDK 11 LTS that could be used. Here we recall How to uninstall JDK if you need to upgrade or downgrade JDK version.

On Ubuntu or Debian platform

From the Oracle website, download jdk-15.0.2_linux-x64_bin.tar.gz. After JDK download and extraction of the files from the archive, you may set JAVA_HOME environment var to help cmake to detect JDK.

$ tar xvzf jdk-15.0.2_linux-x64_bin.tar.gz -C $VISP_WS
$ echo 'export JAVA_HOME=$VISP_VS/jdk-11.0.10' >> ~/.bashrc
$ echo 'export PATH=${JAVA_HOME}/bin:${PATH}' >> ~/.bashrc
$ source ~/.bashrc

After installation check JDK version:

$ java --version
java 15.0.2 2021-01-19

On Mac OSX platform

Warning
On macOS Catalina 10.15.7 with Xcode 12.4, the installation of JDK 11 or 15 from the Oracle website by downloading and installing jdk-11.0.10_osx-x64_bin.dmg or jdk-15.0.2_osx-x64_bin.dmg doesn't allow the detection of JNI necessary to build visp_java.jar. That's why we recommend to install JDK using brew.
$ more ViSP-third-party.txt
  ...
  Java:                          
    ant:                         /usr/local/bin/ant (ver 1.10.9)
    JNI:                         no
Note
If you already have an old JDK version you may remove it before installing OpenJDK:
$ ls /Library/Java/JavaVirtualMachines/
jdk-11.0.10.jdk
Here it shows that jdk-11.0.10 is installed. To remove this version, see How to uninstall JDK.

To install OpenJDK with brew:

  • run:
    $ brew install openjdk
    
  • To know which version is installed:
    $ brew info openjdk
    openjdk: stable 15.0.1 (bottled) [keg-only]
    
  • Now for the system Java wrappers to find this JDK, symlink it with:
    $ sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
    
  • Set JAVA_HOME env var to help JNI headers and libraries detection
    $ echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.bashrc
    $ source ~/.bashrc
    
  • After installation check JDK version:
    $ java --version
    openjdk 15.0.1 2020-10-20
    

On Windows platform

From the Oracle website, download jdk-15.0.2_windows-x64_bin.exe and run the binary. In order to make java.exe available, we had also to add its location C:\Program Files\Java\jdk-15.0.2\bin to the %PATH% environment variable.

After installation check JDK version:

$ java -version
java version 15.0.2 2021-01-19

Install Prerequisites

As a prerequisite, download and install first CMake and Apache Ant, if you don’t have any of these.

  • On Ubuntu/Debian you may run:
    $ sudo apt-get install cmake-curses-gui ant
    
  • On Fedora/CentOS you may run:
    $ sudo yum install gcc-c++ cmake ant
    
  • On MacOS/OSX you may run:
    $ brew cask install java
    $ brew install cmake ant
    

Install ViSP from source code

Getting ViSP source code

There are different ways to get ViSP source code:

  • You can download the latest release as a zip or a tarball. Once downloaded, uncompress the file using either
    $ tar xvzf visp-x.y.z.tar.gz -C $VISP_WS
    
    or
    $ unzip visp-x.y.z.zip -d $VISP_WS
    
  • You can also download a daily snapshot. Once downloaded, uncompress the file using
    $ tar xvzf visp-snapshot-yyyy-mm-dd.tar.gz -C $VISP_WS
    
  • Or you get the cutting-edge ViSP from GitHub repository using the following command
    $ cd $VISP_WS
    $ git clone https://github.com/lagadic/visp.git
    

We suppose now that ViSP source is in the directory $VISP_WS/visp. The following should be adapted if you downloaded ViSP from a zip or tarball. In that case, the source is rather in something like $VISP_WS/visp-x.y.z.

Configuring ViSP from source

  • In the workspace, create first a directory named visp-build that will contain all the build material; generated Makefiles, object files, output libraries and binaries.
    $ mkdir $VISP_WS/visp-build
    
  • Enter the visp-build folder and configure the build:
    $ cd $VISP_WS/visp-build
    $ cmake ../visp
    
    A more versatile way to configure the build is to use ccmake, the CMake GUI:
    $ ccmake ../visp
    
    The following image shows that this command allows to configure (just by pressing [c] key) the build in a more advanced way where some options could be easily turned ON/OFF. It allows also to see which are the 3rd parties that will be used. To generate the makefiles, just press [g] key in the ccmake gui.
    img-ccmake-ubuntu-all.png
    Snapshot of the "ccmake ../visp" command used to configure ViSP.

In $VISP_WS/visp-build/ViSP-third-party.txt you should find something similar to the following snapshot that shows that python, ant and JNI are found:

$ more ViSP-third-party.txt
==========================================================
General configuration information for ViSP 3.3.1

  Version control:               3.2.0-1408-g4d4323805-dirty

  Platform:
    Timestamp:                   2021-02-17T14:23:18Z
    Host:                        Linux 5.4.0-56-generic x86_64
    CMake:                       3.16.3
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  C/C++:
    Built as dynamic libs?:      yes
    C++ Compiler:                /usr/bin/c++  (ver 9.3.0)
    C++ flags (Release):         -Wall -Wextra -fopenmp -std=c++14 -fvisibility=hidden -msse2 -msse3 -mssse3 -fPIC -O3 -DNDEBUG
    C++ flags (Debug):           -Wall -Wextra -fopenmp -std=c++14 -fvisibility=hidden -msse2 -msse3 -mssse3 -fPIC -g
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -Wall -Wextra -fopenmp -std=c++14 -fvisibility=hidden -msse2 -msse3 -mssse3 -fPIC -O3 -DNDEBUG
    C flags (Debug):             -Wall -Wextra -fopenmp -std=c++14 -fvisibility=hidden -msse2 -msse3 -mssse3 -fPIC -g
    Linker flags (Release):
    Linker flags (Debug):

  ViSP modules:
    To be built:                 core gui imgproc io java_bindings_generator klt me sensor ar blob robot visual_features vs vision detection mbt tt tt_mi java
    Disabled:                    -
    Disabled by dependency:      -
    Unavailable:                 -

  Python (for build):            /usr/bin/python3

  Java:
    ant:                         /usr/bin/ant (ver 1.10.7)
    JNI:                         $VISP_WS/jdk-15.0.2/include $VISP_WS/jdk-15.0.2/include/linux $VISP_WS/jdk-15.0.2/include

Building ViSP libraries

  • To build ViSP modules and java libraries on Linux, proceed with:
    $ cd $VISP_WS/visp-build
    $ make -j$(nproc) visp_java
    
  • To build ViSP modules and java libraries on MacOS/OSX, proceed with:
    $ cd $VISP_WS/visp-build
    $ make -j$(sysctl -n hw.ncpu) visp_java
    

Note that ViSP Java ARchive is now available in $VISP_WS/visp-build/bin/visp-340.jar.

Setting Up ViSP Java in Eclipse

Install the latest Eclipse version

Download the latest Eclipse version at the Eclipse Download page choosing the Eclipse IDE for Java Developers version. You don’t need to install anything. Extract the downloaded compressed file and put the resulting folder wherever you want to, for example in $VISP_WS/eclipse.

Creating a user library

Open Eclipse and select a workspace location of your choice, for example in $VISP_WS/eclipse/eclipse-workspace and press Launch button.

img-tutorial-java-eclipse-workspace.jpg

Now we propose to create a ViSP user library ready to be used on all your next Java projects. To this end,

  • if you are on OS X enter "Eclipse \> Preferences..." menu
  • otherwise enter "Window \> Preferences" menu:
    img-tutorial-java-eclipse1.jpeg
    Open Preferences panel in Eclipse

In the Preferences panel navigate under "Java \> Build Path \> User Libraries" and choose New. Enter a name for the library (e.g visp) and press OK button.

img-tutorial-java-eclipse2.jpeg
Create a new User Library

Press "Add External JARs" button, browse to select $VISP_WS/visp-build/bin/visp-340.jar from your computer. After adding the jar, select "Native library location", press first "Edit", press "External Folder", browse to select the folder $VISP-WS/visp_build/lib containing ViSP libraries and finally press OK button. We recall that the libraries have the extension .so in linux, .dylib in MacOS and .dll in Windows.

img-tutorial-java-eclipse3.jpeg
Add jar and native libraries to User Library

Once done, press "Apply and Close" button.

Tips & Tricks

How to uninstall JDK

Here we give here some tips to uninstall JDK to be able to downgrade or upgrade JDK version.

On Ubuntu or Debian platform

On Ubuntu or Debian platform there is nothing more to do than removing the folder containing JDK.

$ rm -rf $VISP_VS/jdk-11.0.6

On Mac OSX platform

To uninstall JDK on Mac OSX, you must have administrator privileges and remove the directory whose name matches the following format: /Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdk. You can proceed using:

$ sudo mv /Library/Java/JavaVirtualMachines/jdk-13.jdk/ /tmp

and/or:

$ sudo mv /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/ /tmp

On Windows platform

To uninstall JDK on Windows, click Start menu, select "Settings \> System \> Apps & features". Select the program to unsinstall like Java(TM) SE Development Kit 13.0 (64-bit), then click its Uninstall button. Respond to the prompts to complete the uninstall.

How to delete an Eclipse workspace

To remove existing Eclipse workspaces, enter "Preferences \> General \> Startup & Shudown \> Workspaces" menu, select the workspace to remove and press Remove button and then Apply and Close button.

img-tutorial-java-eclipse-remove-workspace.jpeg

Note that this does not actually delete the files from the system, it simply removes it from the list of suggested workspaces. You need to remove the workspace directory by hand.

Next tutorial

You are now ready to follow Tutorial: First java application with ViSP.