Linux中gdal的使用

四:Ubuntu中GDAL的使用(JavaWeb项目使用)

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

cp /home/zcx/Desktop/XQ/gdal-3.2.1/swig/java/gdal.jar  /usr/local/pgsql/plugin/gdal/share/java
cp /home/zcx/Desktop/XQ/gdal-3.2.1/swig/java/.libs/*.so  /usr/local/pgsql/plugin/gdal/share/java

2:配置java.library.path

java.library.path=/usr/java/packages/lib/amd64,放置libgdalalljni.so到此目录, javaWeb项目从这里加载libgdalalljni.so动态库(一般这个java.library.path指的是:jre/lib/amd64)

cp /usr/local/src/gdal-3.0.4/swig/java/.libs/*.so  /usr/local/lib/jvm/jdk1.8.0_351/jre/lib/amd64

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

cp /home/zcx/Desktop/XQ/gdal-3.2.1/swig/java/gdal.jar  /usr/local/lib/jvm/jdk1.8.0_351/jre/lib/ext
​
vi /etc/profile
CLASS_PATH=$JAVA_HOME/jre/lib/ext/gdal.jar:$CLASS_PATH
source /etc/profile

4:将swig下的gdal.jar和libgdalalljni.so放到tomcat下的webapp的lib中

可能出现的问题

错误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

gdal.jar未放到tomcat的项目资源中

参考:https://blog.csdn.net/qq_43961619/article/details/124627871

java程序创建目录文件权限问题:

改为umask="0000"

tomcat关闭不完全问题:

1:在PRGDIR=dirname "$PRG"后面加:

if [ -z "$CATALINA_PID" ]; then
    CATALINA_PID=$PRGDIR/CATALINA_PID
    cat $CATALINA_PID 
fi

2:在最后一行加 -force:

exec "$PRGDIR"/"$EXECUTABLE" stop -force "$@"
posted @ 2023-03-07 13:51  一份人间烟火  阅读(730)  评论(0编辑  收藏  举报