4、Linux系统编译、发布gdal项目

一、 Windows部署GDAL
二、 JAVA开发环境整合GDAL
三、 部署Java集成gdal项目
四、 Linux系统编译、发布gdal项目

1、参照CentOS7 Linux(CentOS)编译安装Postgresql 12.2+Postgis-3.0.1一文,按照以下两节安装

三、编译GDAL依赖
四、编译GDAL 3.0.4

2、编译生成gdal.jar

2.1 配置java.opt

修改文件:/usr/local/src/gdal-3.0.4/swig/java/java.opt,修改JAVA_HOME的值为java的根目录
JAVA_HOME = /usr/java/jdk1.8.0_221

2.2 编译

cd /usr/local/src/gdal-3.0.4/swig/java
make && make install

3、JavaWeb应用的 gdal环境配置

1、整理文件,把生成的文件放置到gdal/java目录

mkdir -p /usr/local/pgsql/plugin/gdal/java
cp /usr/local/src/gdal-3.0.4/swig/java/gdal.jar  /usr/local/pgsql/plugin/gdal/java
cp /usr/local/src/gdal-3.0.4/swig/java/.libs/*.so /usr/local/pgsql/plugin/gdal/java

2、在centos下, java.library.path=/usr/java/packages/lib/amd64,放置libgdalalljni.so到此目录,javaWeb项目从这里加载libgdalalljni.so动态库

cp /usr/local/src/gdal-3.0.4/swig/java/.libs/*.so /usr/java/packages/lib/amd64

3、把/swig/java中生成的gdal.jar文件复制到jre/lib/ext,jvm启动加载

cp /usr/local/src/gdal-3.0.4/swig/java/gdal.jar  /usr/java/jdk1.8.0_221/jre/lib/ext

vi /etc/profile
CLASS_PATH=$JAVA_HOME/jre/lib/ext/gdal.jar:$CLASS_PATH
source /etc/profile

4、在/usr/local/gdal-3.0.4/swig/java/目录下复制gdal.jar、libgdalalljni.so文件到项目resources/gdal/linux

image.png

5、启动JavaWeb看看吧

  • 载入动态库libgdalalljni.so
    http://192.168..128:8080/api/gdal/load

  • 注册gdal驱动
    http://192.168..128:8080/api/gdal/register

  • 测试gdal
    http://192.168..128:8080/api/gdal/test

可能出现的问题

错误1: java.lang.UnsatisfiedLinkError: Native Library /usr/java/packages/lib/amd64/libgdalalljni.so already loaded in another classloader

jvm启动时已经加载过libgdalalljni.so,不能能再次加载了,在linux系统上无需代码加载libgdalalljni.so

错误2:libpq.so.5: cannot open shared object file: No such file or directory 原因是未设置pg库到系统动态库配置请设置ld.so.conf

echo '/usr/local/pgsql/lib' >> /etc/ld.so.conf
ldconfig

错误3:nested exception is java.lang.UnsatisfiedLinkError: org.gdal.ogr.ogrJNI.RegisterAll()V

gdal.jar未放置到/usr/java/jdk1.8.0_221/jre/lib/ext

vi /etc/profile
CLASS_PATH=$JAVA_HOME/jre/lib/ext/gdal.jar:$CLASS_PATH
source /etc/profile

你可能感兴趣的:(4、Linux系统编译、发布gdal项目)