首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Geotools/Maven依赖顺序

Geotools/Maven依赖顺序
EN

Stack Overflow用户
提问于 2015-07-20 20:03:55
回答 1查看 832关注 0票数 1

我一直在试图找出以下异常的原因

org.geotools.feature.SchemaException:错误解码srs: 4326

我不断地看到人们说我需要以下的依赖

代码语言:javascript
运行
复制
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-hsql</artifactId>
        <version>${geotools.version}</version>
    </dependency>

我使用m2e eclipse插件来构建jar,并且我总是能够通过eclipse成功地运行我的应用程序,但是当我尝试从命令行运行jar时,我会得到异常,因此我知道它必须与构建jar的方式有关。我用下面的代码创建了一个简单的应用程序来复制这个问题。

代码语言:javascript
运行
复制
import org.geotools.data.DataUtilities;
import org.geotools.feature.SchemaException;
import org.opengis.feature.simple.SimpleFeatureType;


public class Main {

/**
 * @param args
 * @throws SchemaException 
 */
public static void main(String[] args) throws SchemaException {

    SimpleFeatureType lineFeatureType = DataUtilities.createType("LINE", "geom:LineString:srid=4326,name:String");

    System.out.println("Success!");
}

}

我的pom文件看起来像这样

代码语言:javascript
运行
复制
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupid</groupId>
<artifactId>artifactid</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>example</name>
<packaging>jar</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <geotools.version>12-RC1</geotools.version>
</properties>

<dependencies>
<!--        <dependency> -->
<!--            <groupId>org.geotools</groupId> -->
<!--            <artifactId>gt-shapefile</artifactId> -->
<!--            <version>${geotools.version}</version> -->
<!--        </dependency> -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-hsql</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geometry</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-shapefile</artifactId>
        <version>${geotools.version}</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>OSGEO GeoTools repo</id>
        <url>http://download.osgeo.org/webdav/geotools</url>
    </repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-my-jar-with-dependencies</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- bind to the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

我开始看到的是,如果我的依赖关系是按照这个顺序

代码语言:javascript
运行
复制
<dependencies>
<!--        <dependency> -->
<!--            <groupId>org.geotools</groupId> -->
<!--            <artifactId>gt-shapefile</artifactId> -->
<!--            <version>${geotools.version}</version> -->
<!--        </dependency> -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-hsql</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geometry</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-shapefile</artifactId>
        <version>${geotools.version}</version>
    </dependency>
</dependencies>

然后,当我从命令行执行jar时,我会看到“成功!”例外情况不会发生。但是如果我的依赖关系是按照这个顺序

代码语言:javascript
运行
复制
<dependencies>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-shapefile</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-hsql</artifactId>
        <version>${geotools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geometry</artifactId>
        <version>${geotools.version}</version>
    </dependency>
<!--        <dependency> -->
<!--            <groupId>org.geotools</groupId> -->
<!--            <artifactId>gt-shapefile</artifactId> -->
<!--            <version>${geotools.version}</version> -->
<!--        </dependency> -->
</dependencies>

然后就会出现异常。

我认为依赖关系的顺序在maven项目中并不重要。有人能解释一下这是怎么回事吗?我很感谢你的反馈!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-21 08:39:53

一般来说,mvn并不关心依赖关系的顺序,这是正确的,但是它确实按照pom文件中显示的顺序对它们进行了处理。

当您正在打包jars时,这一点变得非常重要,因为默认的maven包程序不能很好地处理GeoTools用来加载工厂的SPI文件,在本例中是EPSG引用工厂。

如果您使用Maven阴影包装机,它将正确地构建文件。在GeoTools常见问题中有一个更长的讨论和一个例子。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31525365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档