1. 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.
2. Create a workspace
2.1. On Ubuntu, Debian or Mac OSX
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/3rdparty
2.2. On Windows
Follow instructions to 2. Create a workspace on Windows.
We suppose now that you have set %VISP_WS% var.
3. Install Java Development Kit (JDK)
- Note
- At the time this tutorial was updated, the lastest Long Term Support Java SE Development Kit (JDK) is version 21. Here we recall 8.1. How to uninstall JDK if you need to upgrade or downgrade JDK version.
3.1. On Ubuntu or Debian
From the Oracle website, download JDK 21 the latest Long Term Support release of the Java SE Platform. There exists also JDK 23 the latest release, but we experienced issues when using it in an Eclipse project on Ubuntu. That's why at the time this tutorial was updated, we considered JDK 21 and downloaded jdk-21_linux-x64_bin.tar.gz file. 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 ~/Downloads/jdk-21_linux-x64_bin.tar.gz -C $VISP_WS/3rdparty
$ echo 'export JAVA_HOME=$VISP_WS/3rdparty/jdk-21.0.6' >> ~/.bashrc
$ echo 'export PATH=${JAVA_HOME}/bin:${PATH}' >> ~/.bashrc
$ source ~/.bashrc
After installation check JDK version:
$ java --version
java 21.0.6 2025-01-21 LTS
Java(TM) SE Runtime Environment (build 21.0.6+8-LTS-188)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.6+8-LTS-188, mixed mode, sharing)
3.2. On Mac OSX
There are two different ways to install JDK on Mac OSX. We recommend the way using DMG installer.
3.2.1. Install JDK with DMG installer
Navigate to Oracle website and download the DMG installer that match your OS. At the time this tutorial was updated, we downloaded jdk-23_macos-aarch64_bin.dmg that corresponds to the JDK 23 version for a Macbook Pro M1.
After installation, check that JDK and java are well detected:
$ java -version
java version "23.0.2" 2025-01-21
3.2.2. Install OpenJDK with brew
- 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 8.1. How to uninstall JDK.
To install OpenJDK with brew:
- run:
- To know which version is installed:
$ brew info openjdk
openjdk: stable 23.0.2 (bottled) [keg-only]
- Now for the system Java wrappers to find this JDK, symlink it with:
$ sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
- Note
- Depending on the OpenJDK version, the symlink instruction can differ. To know which one is to use, follow instructions provided by brew info openjdk. At the time this tutorial was updated, we got:
$ brew info openjdk
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/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)' >> ~/.zshrc
$ source ~/.zshrc
- After installation check that OpenJDK and java are well detected:
$ java --version
openjdk 23.0.2 2025-01-21
3.3. On Windows
From the Oracle website, download JDK 23 to get jdk-23_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-17.0.2\bin to the %PATH% environment variable.
After installation check JDK version:
C:> java -version
java version 23.0.2 2025-01-21
4. Install the latest Eclipse version
Download the latest Eclipse version at the Eclipse Download page choosing the Eclipse IDE for Java Developers version.
4.1. On Ubuntu, Debian and Mac OSX
On Ubuntu, Debian or Mac OSX 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/3rdparty/eclipse.
We suppose here that you have Eclipse installed $VISP_WS/3rdparty/eclipse:
$ ls $VISP_WS/3rdparty/eclipse
artifacts.xml configuration dropins eclipse eclipse.ini features icon.xpm p2 plugins readme
4.2. On Windows
After downloading Eclipse simply open the installer and follow default installation instructions. At the time this tutorial was updated we downloaded "Eclipse IDE 2024-12 R", getting eclipse-inst-jre-win64.exe installer.
Eclipse was installed by default in C:\Users\USERNAME%\eclipse\java-2024-12\eclipse folder.
5. Install Prerequisites
To build ViSP for java you have also to install CMake, Apache Ant, and Python 3. If you don’t have any of these do the following:
5.1. On Ubuntu/Debian
$ sudo apt-get install cmake-curses-gui ant python3
5.2. On Fedora/CentOS
$ sudo dnf install gcc-c++ cmake ant python3
5.3. On Mac OSX
$ brew install cmake ant python3
5.4. On Windows
- Download the latest CMake release for Windows win64-x64 platform from http://www.cmake.org. At the time this tutorial was written it was the file cmake-4.0.0-rc1-windows-x86_64.msi. To install just double click on the msi file.
- Download the latest Python 3 release for Windows from https://www.python.org/downloads/. At the time this tutorial was written, it was Python 3.13.2.
- There is also Apache Ant that is needed. Download Apache Ant binary distribution from https://ant.apache.org/bindownload.cgi. At the time this tutorial was updated we downloaded apache-ant-1.10.15-bin.zip file. Unzip the file for example in C:\Users\USERNAME%\apache-ant-1.10.15-bin. To help Ant detection, set ANT_HOME var to your installation folder. In our case it becomes
C:> setx ANT_HOME C:\Users\%USERNAME%\apache-ant-1.10.15-bin
You need also to add "ANT_HOME%\bin" to the "Path" environment variable. To this end, open the environment variables panel, and modify "Path" accordingly. In our case we added "C:\Users\USERNAME%\apache-ant-1.10.15-bin\bin" folder. - Note
- You can check that the "ANT_HOME%" variable is correctly positioned by checking that the ant.bat file is in the "ANT_HOME%\bin" folder.
6. Build ViSP from source code
6.1. 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.
6.2. Configuring ViSP from source
6.3. Building ViSP libraries
Depending on you platform, you can now build visp_java module:
- On Ubuntu/Debian like, proceed with:
$ cd $VISP_WS/visp-build
$ make -j$(nproc) visp_java
- On macOS, proceed with:
$ cd $VISP_WS/visp-build
$ make -j$(sysctl -n hw.ncpu) visp_java
- On Windows, proceed with:
C:> cd %VISP_WS%\visp-build
C:> cmake --build . --config Release --target visp_java
Note that ViSP Java ARchive is now available in $VISP_WS/visp-build/bin/visp-340.jar.
7. Creating a user library in Eclipse
Open Eclipse and select a workspace location of your choice, for example in $VISP_WS/eclipse-workspace and press Launch button.
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:
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.
Create a new User Library
Press "Add External JARs" button, browse to select $VISP_WS/visp-build/bin/visp-361.jar from your computer.
Add external JARs
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.
Add native library location
Once done, press "Apply and Close" button.
8. Tips & Tricks
8.1. 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 remove first the folder containing JDK.
$ rm -rf $VISP_VS/jdk-11.0.6
Then in ~/.bashrc remove any reference to JAVA_HOME env var deleting the lines similar to: export JAVA_HOME=$VISP_VS/jdk-11.0.6
export PATH=${JAVA_HOME}/bin:${PATH}
- On macOS 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.
8.2. 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.
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.
9. Next tutorial
You are now ready to follow Tutorial: First java application with ViSP.