GeoTools Eclipse 快速入门02

2024-02-24 18:32

本文主要是介绍GeoTools Eclipse 快速入门02,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

我们继续上节的翻译,GeoTools Eclipse 快速入门,今天开始这部分内容的第二节(向项目中添加Jar包)

Adding Jars to your Project

The pom.xml file is used to describe the care and feeding of your maven project; we are going to focus on the dependencies needed for your project 

When downloading jars maven makes use of a "local repository" to store jars.

PLATFORM LOCAL REPOSITORY
Windows XP: C:\Documents and Settings\You\.m2\repository
Windows: C:\Users\You\.m2repository
Linux and Mac: ~/.m2/repository

To download jars maven makes use of public maven repositories on the internet where projects such as GeoTools publish their work.

1.Open up pom.xml in your new project. You can see some of the information we entered earlier.


2.This editor allows you to describe all kinds of things; in the interest of time we are going to skip the long drawn out explanation and ask you to click on thepom.xml/tab.

3.To make use of GeoTools we are going to add three things to this pom.xml file.

4.At the top after module Version add a properties element defining the version of GeoTools we want to use. This workbook was written for 17-SNAPSHOT although you may wish to try a different version.

For production a stable release is recommended:

    <properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><geotools.version>15.1</geotools.version></properties>
To make use of nightly build set the  geotools.version property to 17-SNAPSHOT.

    <properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!-- use the latest snapshot --><geotools.version>17-SNAPSHOT</geotools.version></properties>
5.We are going to add a dependence to GeoTools gt-main and gt-swing jars.Note we are making use of the geotools.version defined above.

    <dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.geotools</groupId><artifactId>gt-shapefile</artifactId><version>${geotools.version}</version></dependency><dependency><groupId>org.geotools</groupId><artifactId>gt-swing</artifactId><version>${geotools.version}</version></dependency></dependencies>
6.Finally we need to list the external repositories where maven can download GeoTools and other required jars from.

    <repositories><repository><id>maven2-repository.dev.java.net</id><name>Java.net repository</name><url>http://download.java.net/maven/2</url></repository><repository><id>osgeo</id><name>Open Source Geospatial Foundation Repository</name><url>http://download.osgeo.org/webdav/geotools/</url></repository></repositories>

Note

If you are using a nightly build (such as 17-SNAPSHOT) and add a reference to the snapshot repository.

    <repositories><repository><id>maven2-repository.dev.java.net</id><name>Java.net repository</name><url>http://download.java.net/maven/2</url></repository><repository><id>osgeo</id><name>Open Source Geospatial Foundation Repository</name><url>http://download.osgeo.org/webdav/geotools/</url></repository><repository><snapshots><enabled>true</enabled></snapshots><id>boundless</id><name>Boundless Maven Repository</name><url>http://repo.boundlessgeo.com/main</url></repository></repositories>
7.GeoTools now requires Java 8 language level features(eg.lambdas) - you need to tell Maven to use the 1.8 source level.

    <build><plugins><plugin><inherited>true</inherited><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>
8.For comparison here is the completed pom.xml file for download.

   You may find cutting and pasting to be easier than typing, you can choose Source -> Fomat to fix indentation 

Tips:

  • If maven has trouble downloading any jar; you can try again by selecting Project ‣ Update All Maven Dependencies.
  • If the dependencies do not update automatically use Project ‣ Clean

向您的项目中添加Jar包

pom.xml文件用来描述您的Maven 项目中所关注和依赖的东西;我们将着眼于您项目中的依赖关系。

当您下载jar包时,maven 会用"本地仓库"("local repository")来存储这些jar包。

平台 本地仓库路径
Windows XP: C:\Documents and Settings\You\.m2\reposity
Windows: C:\Users\You\.m2repository
Linux and Mac: ~/.m2/repository

Maven 会到网上公用的存储库,比如GeoTools发布项目的库;来下载jar包。

1、在您新建的项目中打开pom.xml 文件,如您所见,有些信息已经事先填好了。


2、编辑器允许您对各种事物进行描述;由于时间缘故,我们跳过长篇大论的描述并请您直接点击pom.xml选项卡

3、为了使用GeoTools,我们要向 pom.xml 文件中添加三处改动。

4、在开头,模块版本的后面添加一个属性元素来定义我们要使用的GeoTools的版本号。此教程是针对 17—快照版编写的,尽管如此,您还可以尝试使用其他的版本。

我们推荐使用一个稳定的发行版产品:

    <properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><geotools.version>15.1</geotools.version></properties>
由于我们每天(都经常会)构建项目,不妨将geotools的版本 geotools.version 设置为 17- SNAPSHOT 快照版比较合适。

    <properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!-- use the latest snapshot --><geotools.version>17-SNAPSHOT</geotools.version></properties>
5、我们将为 gt-main   和 gt-swing 两个jar包添加依赖关系,注意,我们使用的是上面提到的geotool的版本。

    <dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.geotools</groupId><artifactId>gt-shapefile</artifactId><version>${geotools.version}</version></dependency><dependency><groupId>org.geotools</groupId><artifactId>gt-swing</artifactId><version>${geotools.version}</version></dependency></dependencies>
6、最后,我们需要列出GeoTools 和其他需要用到的jar包的下载源——外部存储库  repositories.

    <repositories><repository><id>maven2-repository.dev.java.net</id><name>Java.net repository</name><url>http://download.java.net/maven/2</url></repository><repository><id>osgeo</id><name>Open Source Geospatial Foundation Repository</name><url>http://download.osgeo.org/webdav/geotools/</url></repository></repositories>

Note

If you are using a nightly build (such as 17-SNAPSHOT) and add a reference to the snapshot repository.

    <repositories><repository><id>maven2-repository.dev.java.net</id><name>Java.net repository</name><url>http://download.java.net/maven/2</url></repository><repository><id>osgeo</id><name>Open Source Geospatial Foundation Repository</name><url>http://download.osgeo.org/webdav/geotools/</url></repository><repository><snapshots><enabled>true</enabled></snapshots><id>boundless</id><name>Boundless Maven Repository</name><url>http://repo.boundlessgeo.com/main</url></repository></repositories>

7、GeoTools 目前需要 Java 8 语言环境支持(比如 lamdas) — 您需要让 Maven 选择 1.8 级别 的源。

    <build><plugins><plugin><inherited>true</inherited><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>
8、为了方便您进行对比,这里提供了 pom.xml 文件的下载链接。

您会发现,剪切和粘贴要比打字方便多了,您可以选择 源 -> 格式 来修复缩进

提示:

  • 如果maven无法下载任何jar; 您可以通过选择 项目 ‣ 更新所有Maven依赖关系 再次尝试 。
  • 如果依赖不能自动更新,可使用 项目 ‣ 清除


这篇关于GeoTools Eclipse 快速入门02的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/742978

相关文章

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

springboot security快速使用示例详解

《springbootsecurity快速使用示例详解》:本文主要介绍springbootsecurity快速使用示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录创www.chinasem.cn建spring boot项目生成脚手架配置依赖接口示例代码项目结构启用s

解决Java中基于GeoTools的Shapefile读取乱码的问题

《解决Java中基于GeoTools的Shapefile读取乱码的问题》本文主要讨论了在使用Java编程语言进行地理信息数据解析时遇到的Shapefile属性信息乱码问题,以及根据不同的编码设置进行属... 目录前言1、Shapefile属性字段编码的情况:一、Shp文件常见的字符集编码1、System编码

C++快速排序超详细讲解

《C++快速排序超详细讲解》快速排序是一种高效的排序算法,通过分治法将数组划分为两部分,递归排序,直到整个数组有序,通过代码解析和示例,详细解释了快速排序的工作原理和实现过程,需要的朋友可以参考下... 目录一、快速排序原理二、快速排序标准代码三、代码解析四、使用while循环的快速排序1.代码代码1.由快

Win32下C++实现快速获取硬盘分区信息

《Win32下C++实现快速获取硬盘分区信息》这篇文章主要为大家详细介绍了Win32下C++如何实现快速获取硬盘分区信息,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 实现代码CDiskDriveUtils.h#pragma once #include <wtypesbase

Python FastAPI入门安装使用

《PythonFastAPI入门安装使用》FastAPI是一个现代、快速的PythonWeb框架,用于构建API,它基于Python3.6+的类型提示特性,使得代码更加简洁且易于绶护,这篇文章主要介... 目录第一节:FastAPI入门一、FastAPI框架介绍什么是ASGI服务(WSGI)二、FastAP

Spring AI与DeepSeek实战一之快速打造智能对话应用

《SpringAI与DeepSeek实战一之快速打造智能对话应用》本文详细介绍了如何通过SpringAI框架集成DeepSeek大模型,实现普通对话和流式对话功能,步骤包括申请API-KEY、项目搭... 目录一、概述二、申请DeepSeek的API-KEY三、项目搭建3.1. 开发环境要求3.2. mav

Python如何快速下载依赖

《Python如何快速下载依赖》本文介绍了四种在Python中快速下载依赖的方法,包括使用国内镜像源、开启pip并发下载功能、使用pipreqs批量下载项目依赖以及使用conda管理依赖,通过这些方法... 目录python快速下载依赖1. 使用国内镜像源临时使用镜像源永久配置镜像源2. 使用 pip 的并

SpringBoot快速接入OpenAI大模型的方法(JDK8)

《SpringBoot快速接入OpenAI大模型的方法(JDK8)》本文介绍了如何使用AI4J快速接入OpenAI大模型,并展示了如何实现流式与非流式的输出,以及对函数调用的使用,AI4J支持JDK8... 目录使用AI4J快速接入OpenAI大模型介绍AI4J-github快速使用创建SpringBoot