Java bindings

The GDAL project has SWIG generated Java bindings for GDAL and OGR.

Generally speaking the classes and methods mostly match those of the GDAL and OGR C++ classes. You can find the ​Javadoc of the API of the Java bindings.

Due to the fact the Java garbage collector works in a separate thread from the main thread, it is necessary to configure GDAL with multi-threading support, even if you do not use GDAL API from several Java threads.

How to build bindings

Please consult the CMake Java bindings options paragraph for CMake options controlling how to enable the Java bindings and where to install its artifacts

How to use the bindings

The result of the build of the Java bindings will be both a gdal.jar and a companion / libgdalalljni.dylib / gdalalljni.dll native library. To limit potential compatibility problems, you should ensure that gdal.jar and gdalalljni come from the same GDAL sources.

The native gdalalljni library, as well as the core libgdal library (and its dependencies) should be accessible through the mechanism of the operating system to locate shared libraries. Typically on Linux, this means that the path to those libraries should be set in the LD_LIBRARY_PATH environment variable (or in /etc/ On MacOSX, it should be in the DYLD_LIBRARY_PATH environment variable. And on Windows, in the PATH environment variable.

For example, to test on Linux that the bindings are working, you can lanch, from the build directory:

java -classpath $PWD/swig/java/gdal.jar:$PWD/swig/java/build/apps gdalinfo

On Windows:

set PATH=%CD%;%CD%\swig\java;%PATH%
java -classpath %CD%\swig\java\gdal.jar;%CD%\swig\java\build\apps gdalinfo

Maven Users

The Java bindings are available from the ​`Maven Central <>`__ repository. All that is needed is to declare a dependency.