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

相关文章

从入门到精通MySQL联合查询

《从入门到精通MySQL联合查询》:本文主要介绍从入门到精通MySQL联合查询,本文通过实例代码给大家介绍的非常详细,需要的朋友可以参考下... 目录摘要1. 多表联合查询时mysql内部原理2. 内连接3. 外连接4. 自连接5. 子查询6. 合并查询7. 插入查询结果摘要前面我们学习了数据库设计时要满

从入门到精通C++11 <chrono> 库特性

《从入门到精通C++11<chrono>库特性》chrono库是C++11中一个非常强大和实用的库,它为时间处理提供了丰富的功能和类型安全的接口,通过本文的介绍,我们了解了chrono库的基本概念... 目录一、引言1.1 为什么需要<chrono>库1.2<chrono>库的基本概念二、时间段(Durat

解析C++11 static_assert及与Boost库的关联从入门到精通

《解析C++11static_assert及与Boost库的关联从入门到精通》static_assert是C++中强大的编译时验证工具,它能够在编译阶段拦截不符合预期的类型或值,增强代码的健壮性,通... 目录一、背景知识:传统断言方法的局限性1.1 assert宏1.2 #error指令1.3 第三方解决

Linux如何快速检查服务器的硬件配置和性能指标

《Linux如何快速检查服务器的硬件配置和性能指标》在运维和开发工作中,我们经常需要快速检查Linux服务器的硬件配置和性能指标,本文将以CentOS为例,介绍如何通过命令行快速获取这些关键信息,... 目录引言一、查询CPU核心数编程(几C?)1. 使用 nproc(最简单)2. 使用 lscpu(详细信

从入门到精通MySQL 数据库索引(实战案例)

《从入门到精通MySQL数据库索引(实战案例)》索引是数据库的目录,提升查询速度,主要类型包括BTree、Hash、全文、空间索引,需根据场景选择,建议用于高频查询、关联字段、排序等,避免重复率高或... 目录一、索引是什么?能干嘛?核心作用:二、索引的 4 种主要类型(附通俗例子)1. BTree 索引(

Redis 配置文件使用建议redis.conf 从入门到实战

《Redis配置文件使用建议redis.conf从入门到实战》Redis配置方式包括配置文件、命令行参数、运行时CONFIG命令,支持动态修改参数及持久化,常用项涉及端口、绑定、内存策略等,版本8... 目录一、Redis.conf 是什么?二、命令行方式传参(适用于测试)三、运行时动态修改配置(不重启服务

MySQL DQL从入门到精通

《MySQLDQL从入门到精通》通过DQL,我们可以从数据库中检索出所需的数据,进行各种复杂的数据分析和处理,本文将深入探讨MySQLDQL的各个方面,帮助你全面掌握这一重要技能,感兴趣的朋友跟随小... 目录一、DQL 基础:SELECT 语句入门二、数据过滤:WHERE 子句的使用三、结果排序:ORDE

一文详解如何在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