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虚拟环境完全指南

《从入门到精通详解Python虚拟环境完全指南》Python虚拟环境是一个独立的Python运行环境,它允许你为不同的项目创建隔离的Python环境,下面小编就来和大家详细介绍一下吧... 目录什么是python虚拟环境一、使用venv创建和管理虚拟环境1.1 创建虚拟环境1.2 激活虚拟环境1.3 验证虚

Python多线程实现大文件快速下载的代码实现

《Python多线程实现大文件快速下载的代码实现》在互联网时代,文件下载是日常操作之一,尤其是大文件,然而,网络条件不稳定或带宽有限时,下载速度会变得很慢,本文将介绍如何使用Python实现多线程下载... 目录引言一、多线程下载原理二、python实现多线程下载代码说明:三、实战案例四、注意事项五、总结引

C#使用Spire.XLS快速生成多表格Excel文件

《C#使用Spire.XLS快速生成多表格Excel文件》在日常开发中,我们经常需要将业务数据导出为结构清晰的Excel文件,本文将手把手教你使用Spire.XLS这个强大的.NET组件,只需几行C#... 目录一、Spire.XLS核心优势清单1.1 性能碾压:从3秒到0.5秒的质变1.2 批量操作的优雅

Java List 使用举例(从入门到精通)

《JavaList使用举例(从入门到精通)》本文系统讲解JavaList,涵盖基础概念、核心特性、常用实现(如ArrayList、LinkedList)及性能对比,介绍创建、操作、遍历方法,结合实... 目录一、List 基础概念1.1 什么是 List?1.2 List 的核心特性1.3 List 家族成

Mybatis-Plus 3.5.12 分页拦截器消失的问题及快速解决方法

《Mybatis-Plus3.5.12分页拦截器消失的问题及快速解决方法》作为Java开发者,我们都爱用Mybatis-Plus简化CRUD操作,尤其是它的分页功能,几行代码就能搞定复杂的分页查询... 目录一、问题场景:分页拦截器突然 “失踪”二、问题根源:依赖拆分惹的祸三、解决办法:添加扩展依赖四、分页

c++日志库log4cplus快速入门小结

《c++日志库log4cplus快速入门小结》文章浏览阅读1.1w次,点赞9次,收藏44次。本文介绍Log4cplus,一种适用于C++的线程安全日志记录API,提供灵活的日志管理和配置控制。文章涵盖... 目录简介日志等级配置文件使用关于初始化使用示例总结参考资料简介log4j 用于Java,log4c

史上最全MybatisPlus从入门到精通

《史上最全MybatisPlus从入门到精通》MyBatis-Plus是MyBatis增强工具,简化开发并提升效率,支持自动映射表名/字段与实体类,提供条件构造器、多种查询方式(等值/范围/模糊/分页... 目录1.简介2.基础篇2.1.通用mapper接口操作2.2.通用service接口操作3.进阶篇3

Python自定义异常的全面指南(入门到实践)

《Python自定义异常的全面指南(入门到实践)》想象你正在开发一个银行系统,用户转账时余额不足,如果直接抛出ValueError,调用方很难区分是金额格式错误还是余额不足,这正是Python自定义异... 目录引言:为什么需要自定义异常一、异常基础:先搞懂python的异常体系1.1 异常是什么?1.2

Python实现Word转PDF全攻略(从入门到实战)

《Python实现Word转PDF全攻略(从入门到实战)》在数字化办公场景中,Word文档的跨平台兼容性始终是个难题,而PDF格式凭借所见即所得的特性,已成为文档分发和归档的标准格式,下面小编就来和大... 目录一、为什么需要python处理Word转PDF?二、主流转换方案对比三、五套实战方案详解方案1:

使用Redis快速实现共享Session登录的详细步骤

《使用Redis快速实现共享Session登录的详细步骤》在Web开发中,Session通常用于存储用户的会话信息,允许用户在多个页面之间保持登录状态,Redis是一个开源的高性能键值数据库,广泛用于... 目录前言实现原理:步骤:使用Redis实现共享Session登录1. 引入Redis依赖2. 配置R