一、安装准备
1、安装jdk:(建议使用下载包进行安装,yum安装方式不好管理),安装路径为/opt/jdk1.7.0_80
2、安装tomcat:(建议使用下载包进行安装,yum安装方式不好管理),安装路径为/opt/tomcat
3、安装swig:yum install -y swig(java在linux上通过swig来调用GDAL)
4、安装java ant:yum -y install ant(编译时需要)
二、安装GDAL
1、创建安装目录
mkdir /usr/local/gis
cd /usr/local/gis
2、安装proj4,GDAL通过该包实现投影
wget ftp://ftp.remotesensing.org/proj/proj-4.6.0.tar.gz
tar -zxvf proj-4.6.0.tar.gz
cd proj-4.6.0
./configure
make
sudo make install
3、安装GDAL
cd ../
wget http://download.osgeo.org/gdal/1.11.4/gdal-1.11.4.tar.gz
tar -xzvf gdal-1.11.4.tar.gz
cd gdal-1.11.4
./configure --with-static-proj4=/usr/local/lib/libproj.la --with-poppler --with-pg --with-curl --with-geos --with-jpeg --with-png --with-expat --with-xerces --with-java=/opt/jdk1.7.0_80 --with-jvm-lib=/opt/jdk1.7.0_80/jre/lib/amd64/server --with-jvm-lib-add-rpath=yes --with-mdb=yes
备注:configure时,需要注意配置proj4和jdk的路径
make
sudo make install
4、编译GDAL java相关的包
cd ./swig/java
vim java.opt
修改:JAVA_HOME = /opt/jdk1.7.0_80
make (会生成gdal.jar包和相关类库)
5、复制刚生成的所有文件(主要是gdal.jar and all .la, .so files)到java lib目录,我的是/opt/jdk1.7.0_80/jre/lib
6、设置环境变量如下
export LD_LIBRARY_PATH=/opt/jdk1.7.0_80/jre/lib
export GDAL_DATA=/usr/local/share/gdal
export CLASSPATH=/opt/jdk1.7.0_80/jre/lib/gdal.jar
其中 GDAL_DATA 可以通过gdal -config --datadir命令获得
7、将/opt/jdk1.7.0_80/jre/lib添加到/ld.so.conf,否则调用gdal时会提示libgdaljni.so.0: cannot open shared object file:
vim /etc/ld.so.conf 添加/opt/jdk1.7.0_80/jre/lib
sudo /sbin/ldconfig
三、java调用GDAL
1、linux eclipse中调试
设置run config,新增两个变量
GDAL_DATA=/usr/local/share/gdal
LD_LIBRARY_PATH=/opt/jdk1.7.0_80/jre/lib
注意run config有两个,run as application和run on server分别都要设置
2、tomcat中运行
修改 catalina.sh,在开头加入
export GDAL_DATA=/usr/local/share/gdal
export LD_LIBRARY_PATH=/opt/jdk1.7.0_80/jre/lib