Do it without saying much
Import pox dependencies in project
<dependency>
<groupId></groupId>
<artifactId>geoserver-manager</artifactId>
<version>1.7.0-pdok2</version>
</dependency>
Some running configurations
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 connection configuration
String url = "http://localhost:8686/geoserver";
String username = "admin";
String passwd = "geoserver";
String ws = "mxleimm"; //The workspace name of the layer to be created and published workspace
String store_name = "mmmmmmmmmmmmmm"; //The data storage name store of the layer to be created and published
//Defend whether the workspace exists. If it does not exist, it will be created
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 already exists,ws :" + ws);
}
//Distinguish whether the data store already exists, and if it does not exist, it will be created
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 file creation status) : " + createStore);
boolean publish = ().publishGeoTIFF(ws, store_name, new File(fileName));
("publish (TIFF file publish status) : " + publish);
} else {
("The data store already exists, store:" + store_name);
}
}
}
OK Open and publish to complete
If you don't understand, please send me a private message