【问题标题】:Using GeoTools without Maven在没有 Maven 的情况下使用 GeoTools
【发布时间】:2015-09-04 21:56:56
【问题描述】:

我使用 maven 构建工具使用 geotools 库编写了一些 java 代码。当我在 maven 项目中将它作为独立的 java 应用程序运行时,这个小代码运行成功。但由于我需要在另一个项目 我没有 maven 的项目中使用这段代码,我将所有 jar 文件从 maven 项目的 Maven Dependencies 文件夹复制到我的另一个项目并将这些添加为外部 jars/dependencies。但是当我在 eclipse 中将它作为 java 应用程序运行时,这段代码不会在新项目中运行。这是这段代码和堆栈跟踪。:

38.    public static void main(String[] args) throws Exception {
39.     File file = new File("path to shapefile");
40.     modifyShapeFile(file);
    ...........................................
    ............................
    }
52.   public static void modifyShapeFile(final File file) throws Exception {
53.     ShapefileDataStore store = (ShapefileDataStore) FileDataStoreFinder
                .getDataStore(file);
54.     SimpleFeatureSource featureSource = store.getFeatureSource();
55.     SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
56.     Transaction transaction = new DefaultTransaction("modify");
57.     featureStore.setTransaction(transaction);
58.     SimpleFeatureType featureType = store.getSchema();
59.     SimpleFeatureBuilder build = new SimpleFeatureBuilder(featureType);
        ........................................................
        .........................................................

堆栈跟踪:

Exception in thread "main" java.lang.NoSuchFieldError: METER
    at org.geotools.referencing.wkt.Parser.parseSpheroid(Parser.java:560)
    at org.geotools.referencing.wkt.Parser.parseDatum(Parser.java:656)
    at org.geotools.referencing.wkt.Parser.parseGeoGCS(Parser.java:867)
    at org.geotools.referencing.wkt.Parser.parseProjCS(Parser.java:913)
    at org.geotools.referencing.wkt.Parser.parseCoordinateReferenceSystem(Parser.java:225)
    at org.geotools.referencing.wkt.Parser.parseCoordinateReferenceSystem(Parser.java:204)
    at org.geotools.referencing.factory.ReferencingObjectFactory.createFromWKT(ReferencingObjectFactory.java:1090)
    at org.geotools.data.PrjFileReader.<init>(PrjFileReader.java:94)
    at org.geotools.data.PrjFileReader.<init>(PrjFileReader.java:68)
    at org.geotools.data.shapefile.ShapefileSetManager.openPrjReader(ShapefileSetManager.java:106)
    at org.geotools.data.shapefile.ShapefileFeatureSource.readAttributes(ShapefileFeatureSource.java:515)
    at org.geotools.data.shapefile.ShapefileFeatureSource.buildFeatureType(ShapefileFeatureSource.java:471)
    at org.geotools.data.shapefile.ShapefileFeatureStore.buildFeatureType(ShapefileFeatureStore.java:131)
    at org.geotools.data.store.ContentFeatureSource.getAbsoluteSchema(ContentFeatureSource.java:340)
    at org.geotools.data.store.ContentFeatureSource.getSchema(ContentFeatureSource.java:309)
    at org.geotools.data.store.ContentDataStore.getSchema(ContentDataStore.java:339)
    at org.geotools.data.store.ContentDataStore.getSchema(ContentDataStore.java:712)
    at org.geotools.data.shapefile.ShapefileDataStore.getSchema(ShapefileDataStore.java:197)
    at com.amazon.marketplacevolumeviewer.shapefile.ModifyShapeFile.modifyShapeFile(ModifyShapeFile.java:58)
    at com.amazon.marketplacevolumeviewer.shapefile.ModifyShapeFile.main(ModifyShapeFile.java:40)

maven 项目的 pom.xml 文件根据本教程:http://docs.geotools.org/latest/userguide/tutorial/quickstart/eclipse.html

这些 jar 文件没有附加源代码,因此我无法跟踪堆栈跟踪。

【问题讨论】:

  • 可能是版本冲突。在 Maven 项目中做一个 mvn dependency:tree,里面可能有同一个库的多个版本吗?
  • 你不能让你的“其他项目”也成为一个Maven项目吗?因为这是 Maven 著名的事情之一:无需复制 jar 文件。
  • 它已经是一个ANT项目,我只需要使用ANT。

标签: java eclipse maven geotools


【解决方案1】:

在使用 GeoTools 时请使用 Maven - 即使是像我这样的开发人员也几乎不可能跟踪 GeoTools 所需的所有依赖项。

至少在 geotools 构建上运行 mvn dependency:list 以显示您需要哪些文件,而不是盲目复制。可能是您需要选择一个插件 jar 及其相关的依赖项。

查看您的错误表明您可能缺少 net.java.dev.jsr-275.jar 中的 Units 系统。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 1970-01-01
    • 2013-12-14
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    相关资源
    最近更新 更多