Search code examples
eclipsemacosmavengdal

Gdal installation on Mac OS


I’m trying to work with Gdal Library and Java in a Mac OS. But I’m new on Goal and I’m not able to make it works.

Also, I’m working with Maven. So I added this dependency on pom.xml

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

In order to test it on Eclipse I create a simple class like below:

import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconstConstants;
import org.gdal.ogr.ogr; 

public class test {
    public static void main(String[] args) {
                gdal.AllRegister(); 
    }
}

When I execute I’m facing with the following error:

Native library load failed. java.lang.UnsatisfiedLinkError: no ogrjni in java.library.path

I tried to fix it all day without success. I just wanna know a simple way to execute Gdal into Eclipse.

PS: I can run Gdal successfully on terminal


Solution

  • GDAL installation

    Install arguments

    Make sure you have installed gdal with java and swig-java arguments.

    brew install gdal --with-java --with-swig-java

    ps: remove your current gdal installation before run the command above.

    You may need some additional arguments. Check all arguments using

    brew info gdal

    Also, you can check the arguments available below.

    --with-armadillo

    Build with Armadillo accelerated TPS transforms.

    --with-complete

    Use additional Homebrew libraries to provide more drivers.

    --with-java

    Build with java support

    --with-libkml

    Build with Google's libkml driver (requires libkml --HEAD or >= 1.3)

    --with-mdb

    Build with Access MDB driver (requires Java 1.6+ JDK/JRE, from Apple or Oracle).

    --with-mysql

    Build with mysql support

    --with-opencl

    Build with OpenCL acceleration.

    --with-postgresql

    Build with postgresql support

    --with-python3

    Build with python3 support

    --with-swig-java

    Build the swig java bindings

    --with-unsupported

    Allow configure to drag in any library it can find. Invoke this at your own risk.

    --without-python

    Build without python2 support

    --HEAD

    Install HEAD version

    Check gdal required dependencies

    Check if you have installed all dependencies required by gdal. Use

    brew info gdal

    to see all dependencies and if you have them installed.

    ==> Dependencies Required: libpng ✔, jpeg ✔, giflib ✔, libtiff ✔, libgeotiff ✔, proj ✔, geos ✔, json-c ✔, libxml2 ✔, pcre ✔, sqlite ✔, freexl ✔, libspatialite ✔

    Optional: postgresql ✘, mysql ✔, armadillo ✔

    ==> Requirements Build: java >= 1.7 ✔, fortran ✔, git ✔

    Optional: java >= 1.7 ✔, python3 ✔

    Maven configuration

    If you're using maven on your project, you need to add gdal dependency in pom.xml.

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

    Environment variable

    You have to add environment variable in Eclipse, like jdeolive said.

    Run > Run Configurations

    then select your application in the left and go to Environment tab.

    Add DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH pointing to /usr/local/opt/gdal/lib.

    That's how I installed gdal and it's working perfectly on macOS 10.12.6.