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

相关文章

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

Python中OpenCV与Matplotlib的图像操作入门指南

《Python中OpenCV与Matplotlib的图像操作入门指南》:本文主要介绍Python中OpenCV与Matplotlib的图像操作指南,本文通过实例代码给大家介绍的非常详细,对大家的学... 目录一、环境准备二、图像的基本操作1. 图像读取、显示与保存 使用OpenCV操作2. 像素级操作3.

eclipse如何运行springboot项目

《eclipse如何运行springboot项目》:本文主要介绍eclipse如何运行springboot项目问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目js录当在eclipse启动spring boot项目时出现问题解决办法1.通过cmd命令行2.在ecl

在Java中基于Geotools对PostGIS数据库的空间查询实践教程

《在Java中基于Geotools对PostGIS数据库的空间查询实践教程》本文将深入探讨这一实践,从连接配置到复杂空间查询操作,包括点查询、区域范围查询以及空间关系判断等,全方位展示如何在Java环... 目录前言一、相关技术背景介绍1、评价对象AOI2、数据处理流程二、对AOI空间范围查询实践1、空间查

MybatisX快速生成增删改查的方法示例

《MybatisX快速生成增删改查的方法示例》MybatisX是基于IDEA的MyBatis/MyBatis-Plus开发插件,本文主要介绍了MybatisX快速生成增删改查的方法示例,文中通过示例代... 目录1 安装2 基本功能2.1 XML跳转2.2 代码生成2.2.1 生成.xml中的sql语句头2

8种快速易用的Python Matplotlib数据可视化方法汇总(附源码)

《8种快速易用的PythonMatplotlib数据可视化方法汇总(附源码)》你是否曾经面对一堆复杂的数据,却不知道如何让它们变得直观易懂?别慌,Python的Matplotlib库是你数据可视化的... 目录引言1. 折线图(Line Plot)——趋势分析2. 柱状图(Bar Chart)——对比分析3

一文教你Java如何快速构建项目骨架

《一文教你Java如何快速构建项目骨架》在Java项目开发过程中,构建项目骨架是一项繁琐但又基础重要的工作,Java领域有许多代码生成工具可以帮助我们快速完成这一任务,下面就跟随小编一起来了解下... 目录一、代码生成工具概述常用 Java 代码生成工具简介代码生成工具的优势二、使用 MyBATis Gen

使用animation.css库快速实现CSS3旋转动画效果

《使用animation.css库快速实现CSS3旋转动画效果》随着Web技术的不断发展,动画效果已经成为了网页设计中不可或缺的一部分,本文将深入探讨animation.css的工作原理,如何使用以及... 目录1. css3动画技术简介2. animation.css库介绍2.1 animation.cs

SpringBoot快速搭建TCP服务端和客户端全过程

《SpringBoot快速搭建TCP服务端和客户端全过程》:本文主要介绍SpringBoot快速搭建TCP服务端和客户端全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录TCPServerTCPClient总结由于工作需要,研究了SpringBoot搭建TCP通信的过程

POI从入门到实战轻松完成EasyExcel使用及Excel导入导出功能

《POI从入门到实战轻松完成EasyExcel使用及Excel导入导出功能》ApachePOI是一个流行的Java库,用于处理MicrosoftOffice格式文件,提供丰富API来创建、读取和修改O... 目录前言:Apache POIEasyPoiEasyExcel一、EasyExcel1.1、核心特性