话不多说直接干
在项目导入pox依赖
<dependency>
<groupId></groupId>
<artifactId>geoserver-manager</artifactId>
<version>1.7.0-pdok2</version>
</dependency>
一些运行配置
package structure;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
/**
* @Classname TestGeoServer
* @Description TODO
* @Date 2019/10/30 8:52
* @Created by MiaoShaoxuan
*/
public class TestGeoServer {
public static void main(String[] args) throws Exception {
//GeoServer的连接配置
String url = "http://localhost:8686/geoserver";
String username = "admin";
String passwd = "geoserver";
String ws = "mxleimm"; //待创建和发布图层的工作区名称workspace
String store_name = "mmmmmmmmmmmmm"; //待创建和发布图层的数据存储名称store
//判断工作区(workspace)是否存在,不存在则创建
URL u = new URL(url);
GeoServerRESTManager manager = new GeoServerRESTManager(u, username, passwd);
GeoServerRESTPublisher publisher = ();
List<String> workspaces = ().getWorkspaceNames();
if (!(ws)) {
boolean createws = (ws);
("create ws : " + createws);
} else {
("workspace已经存在了,ws :" + ws);
}
//判断数据存储(datastore)是否已经存在,不存在则创建
String fileName = "C:\\Users\\VULCAN\\Desktop\\xxxx\\";
RESTDataStore restStore = ().getDatastore(ws, store_name);
if (restStore == null) {
GSGeoTIFFDatastoreEncoder gsGeoTIFFDatastoreEncoder = new GSGeoTIFFDatastoreEncoder(store_name);
("mxleimm");
(new URL("file:" + fileName));
boolean createStore = ().create(ws, gsGeoTIFFDatastoreEncoder);
("create store (TIFF文件创建状态) : " + createStore);
boolean publish = ().publishGeoTIFF(ws, store_name, new File(fileName));
("publish (TIFF文件发布状态) : " + publish);
} else {
("数据存储已经存在了,store:" + store_name);
}
}
}
ok 打开发布就以完成
还有不懂的可以私信我