使用没有Maven的GeoTools

时间:2015-09-03 13:07:11

标签: java eclipse maven geotools

我使用maven构建工具使用geotools库编写了一些java代码。当我在maven项目中将其作为独立的Java应用程序运行时,这个小代码会成功运行。但是因为我需要在另一个我没有maven 的项目中使用这段代码,所以我将maven项目中 Maven Dependencies 文件夹中的所有jar文件复制到我的另一个项目并将它们添加为外部jar / 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文件没有附加源代码,因此我无法跟踪堆栈跟踪。

1 个答案:

答案 0 :(得分:0)

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

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

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