meface/docs/article/gis/geoserver/devEnvironment.md

107 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: GeoServer二级开发-环境配置
date: 2021-04-23
author: ac
sticky: 2
tags:
- GeoServer
categories:
- GIS
---
### 1. 工具
- jdk8geoserver中的各模块都是指定了jdk为1.8所以建议采用jdk8
- mavenjar包管理
- idea
> GeoServer Development requires Java 8, Maven, and git. Due to subtle changes in Java class libraries we require development on Java 8 at this time (although the result is tested on Java 11).
官方是建议使用git来拉取geoserver的源码这里我采用的是直接下载源码的方式。
![image-20210423174254861](../images/geoserver/image-20210423174254861.png)
### 2. 构建项目
进入src目录使用maven命令构建项目
```groovy
//-DskipTests不执行测试用例但编译测试用例类生成相应的class文件至target/test-classes下
mvn -DskipTests install
```
该命令会下载pom文件中的依赖将项目和各模块构建到本地仓库以及编译各模块代码。
![image-20210423175414508](../images/geoserver/image-20210423175414508.png)
> 较旧的版本使用的仓库是`Boundless Maven Repository`,较新的版本是使用`OSGeo Nexus Release Repository`
![image-20210423175448825](../images/geoserver/image-20210423175448825.png)
生成的编译文件在target目录下
<img src="../images/geoserver/image-20210423180211319.png" alt="image-20210423180211319" style="zoom:50%;" />
> 注意:这里生成的annotaions、javacc、javacc-timestamp、jjtree-timestamp在项目中都是作为sources root资源。
### 3. 配置项目
- 编译器使用`Eclipse`
![image-20210423180735102](../images/geoserver/image-20210423180735102.png)
- 配置Maven在IDEA中指定本地的Maven路径确保`mvn install`命令打包的模块jar包在同一个仓库内。后续的开发中需要引用到源码中的模块
![image-20210425113356559](../images/geoserver/image-20210425113356559.png)
- 修改启动参数
<img src="../images/geoserver/image-20210423180852683.png" alt="image-20210423180852683" style="zoom:67%;" />
![image-20210425092340647](../images/geoserver/image-20210425092340647.png)添加一个VM Option参数`-DGEOSERVER_DATA_DIR`,用来指定`GeoServer`应用的【数据目录】;
把`Working directory`修改为`$MODULE_DIR$`,这样各模块的工作路径为模块各自的相对路径。
> 默认的【数据目录】在项目的web模块中
>
> -DGEOSERVER_DATA_DIR=${PROJECT}/src/web/app/src/main/webapp/data/
- 启动项目
![image-20210424115255719](../images/geoserver/image-20210424115255719.png)
在浏览器中输入`http://localhost:8080/geoserver`可以访问刚启动的`GeoServer`应用。
![image-20210424120724804](../images/geoserver/image-20210424120724804.png)
### 4. 项目结构
- `platform` 包的`org.geoserver.platform.Service` 类代表服务提供id、版本、支持的操作等元数据的描述信息。如果两个服务的id和版本相同则会被认为是同一个服务;
- `platform` 包的`org.geoserver.platform.Operation` 类代表某个服务下可以被请求的操作,例如`GetCapabilities`这个类利用Java的反射机制
- `ows` 包的`org.geoserver.ows.Dispatcher` 类处理所有`OWS`的请求;
- `main` 包的`org.geoserver.catalog.Catalog` 接口包含资源访问的方法,这些资源有"Layer""Layer Group""Map""Namesapce""Resource""Store""Style"和"Workspace"
- `main` 包的`org.geoserver.config.GeoServer` 接口包含访问服务器公共配置信息的方法;
### 5. 第三方库
- `GeoTools`可以说是Java语言的`GIS`标准包,它继承了`GeoAPI`,一个符合`OGC`简单要素访问协议([Simple Feature Access](http://www.opengeospatial.org/standards/sfa)的Java包提供了大量`GIS`操作,包括多种格式的空间数据源访问,地图渲染,空间几何操作,`GeoServer`的`GIS`部分完全使用它来实现;
- `Spring`框架GeoServer用它来构建运行时环境通过Spring容器来管理项目的bean实例。我们会在“main”“wcs”“wfs”和“wms”下面看到这样一个文件`applicationContext.xml`这个文件告诉spring框架需要创建哪些类实例以及如何创建
- `FreeMarker`是一个模板引擎, 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页电子邮件配置文件源代码等)的通用工具。我们可以很容易实现对象模型与输出格式的分离,`GeoServer`用它来实现某些HTML文本的输出
![Figure](../images/geoserver/overview.png)
### 参考文章
[1] GeoServer源码解析和扩展 (一)基础篇 https://blog.csdn.net/hnzhangshilong/article/details/6822233
[2] Quickstart https://docs.geoserver.org/latest/en/developer/quickstart/index.html