[GIS] gdal.jar cannot find gdalalljni on Ubuntu

gdaljavaUbuntu

I'm trying org.gdal library on Ubuntu.

<dependency>
  <groupId>org.gdal</groupId>
  <artifactId>gdal</artifactId>
  <version>2.3.3</version>
</dependency>

And got runtime error:
Native library load failed.
java.lang.UnsatisfiedLinkError: no gdalalljni in java.library.path

1) Before this I installed gdal:

sudo apt-get install gdal-bin
sudo apt-get install libgdal-dev

There are no any gdalalljni files installed.

2) export LD_LIBRARY_PATH=/usr/lib
which contains files libgdal.a, libgdal.so, libgdal.so.20 libgdal.so.20.3.2 and not contains any gdalalljni

3) export GDAL_DATA=/usr/share/gdal/2.2

4) set VM options -Djava.library.path="/usr/lib/"

I tried some advices such as http://geoexamples.blogspot.com/2012/05/running-gdal-java.html
Here is about 1.9 release. I not found swig/java directory in my installation of 2.2.

How to use last releases of gdal in java on Ubuntu?

Best Answer

1) First, you should download gdal sources (https://trac.osgeo.org/gdal/wiki/DownloadSource). I placed it to $HOME/gdal-version. Select appropriate version. For me 2.4.2 was installed on Ubuntu 18, and 2.2.4 was installed on Ubuntu 16.

2) Install swig, libgeos-dev and proj4:

sudo apt-get install swig
sudo apt-get install libgeos-dev
sudo apt-get install libproj-dev proj-data proj-bin

3) Go to swig/java folder of sources, edit java.opt: set JAVA_HOME var

4) From sources root run:

./configure --with-java --with-proj=/usr/lib/x86_64-linux-gnu/libproj.la

5) From sources root run: make

6) From swig/java run: make

7) Set environments

export GDAL_BIN=<sources-dir>/apps/
export GDAL_DATA=<sources-dir>/data/
export LD_LIBRARY_PATH=<sources-dir>/swig/java/

8) In java project set VM options -Djava.library.path="/swig/java/"

Related Question