org.getools - NoSuchFieldError: METER

老子叫甜甜 提交于 2021-01-29 14:13:02

问题


A Maven Java project using geotools 15.2 generates an error : NoSuchFieldError: METER

pom.xml

<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-data</artifactId>
    <version>15.2</version>
</dependency>
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-shapefile</artifactId>
    <version>15.2</version>
</dependency>
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-swing</artifactId>
    <version>15.2</version>
</dependency>

When running the code, the error is generated when calling source.getFeatures(Filter.INCLUDE).

Stacktrace

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)

I found out that SI.METER is linked to javax.measure but even if I add it to the project, the error is still present.

The result of mvn dependency:tree is

[INFO] +- com.vividsolutions:jts:jar:1.13:compile
[INFO] +- org.opengis:geoapi:jar:3.0.0:compile
[INFO] |  \- javax.measure:jsr-275:jar:0.9.3:compile
[INFO] +- org.geotools:gt-data:jar:15.2:compile
[INFO] |  +- org.geotools:gt-main:jar:15.2:compile
[INFO] |  |  \- org.geotools:gt-api:jar:15.2:compile
[INFO] |  \- javax.media:jai_core:jar:1.1.3:compile
[INFO] +- org.geotools:gt-shapefile:jar:15.2:compile
[INFO] |  \- org.jdom:jdom:jar:1.1.3:compile
[INFO] \- org.geotools:gt-swing:jar:15.2:compile
[INFO]    +- org.geotools:gt-referencing:jar:15.2:compile
[INFO]    |  +- com.googlecode.efficient-java-matrix-library:core:jar:0.26:compile
[INFO]    |  +- commons-pool:commons-pool:jar:1.5.4:compile
[INFO]    |  +- org.geotools:gt-metadata:jar:15.2:compile
[INFO]    |  |  \- org.geotools:gt-opengis:jar:15.2:compile
[INFO]    |  |     \- net.java.dev.jsr-275:jsr-275:jar:1.0-beta-2:compile
[INFO]    |  +- jgridshift:jgridshift:jar:1.0:compile
[INFO]    |  \- net.sf.geographiclib:GeographicLib-Java:jar:1.44:compile
[INFO]    +- org.geotools:gt-render:jar:15.2:compile
[INFO]    |  +- org.geotools:gt-coverage:jar:15.2:compile
[INFO]    |  |  +- javax.media:jai_imageio:jar:1.1:compile
[INFO]    |  |  +- it.geosolutions.imageio-ext:imageio-ext-tiff:jar:1.1.15:compile
[INFO]    |  |  |  +- it.geosolutions.imageio-ext:imageio-ext-utilities:jar:1.1.15:compile
[INFO]    |  |  |  +- it.geosolutions.imageio-ext:imageio-ext-geocore:jar:1.1.15:compile
[INFO]    |  |  |  |  \- it.geosolutions.imageio-ext:imageio-ext-streams:jar:1.1.15:compile
[INFO]    |  |  |  \- javax.media:jai_codec:jar:1.1.3:compile
[INFO]    |  |  +- org.jaitools:jt-zonalstats:jar:1.4.0:compile
[INFO]    |  |  +- org.jaitools:jt-utils:jar:1.4.0:compile
[INFO]    |  |  +- it.geosolutions.jaiext.affine:jt-affine:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.algebra:jt-algebra:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.bandmerge:jt-bandmerge:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.bandselect:jt-bandselect:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.bandcombine:jt-bandcombine:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.border:jt-border:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.buffer:jt-buffer:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.crop:jt-crop:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.iterators:jt-iterators:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.lookup:jt-lookup:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.mosaic:jt-mosaic:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.nullop:jt-nullop:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.rescale:jt-rescale:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.scale:jt-scale:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.stats:jt-stats:jar:1.0.11:compile
[INFO]    |  |  |  \- com.google.guava:guava:jar:17.0:compile
[INFO]    |  |  +- it.geosolutions.jaiext.translate:jt-translate:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.utilities:jt-utilities:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.warp:jt-warp:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.zonal:jt-zonal:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.binarize:jt-binarize:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.format:jt-format:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.colorconvert:jt-colorconvert:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.errordiffusion:jt-errordiffusion:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.orderdither:jt-orderdither:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.colorindexer:jt-colorindexer:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.imagefunction:jt-imagefunction:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.piecewise:jt-piecewise:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.classifier:jt-classifier:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.rlookup:jt-rlookup:jar:1.0.11:compile
[INFO]    |  |  +- it.geosolutions.jaiext.vectorbin:jt-vectorbin:jar:1.0.11:compile
[INFO]    |  |  \- commons-io:commons-io:jar:2.1:compile
[INFO]    |  \- org.geotools:gt-cql:jar:15.2:compile
[INFO]    \- com.miglayout:miglayout:jar:swing:3.7:compile

Am I missing a dependency ?


回答1:


The answer was found with the help of @IanTurton

I upgraded the geotools version from 15.2 to 20.5. I also added the gt-epsg-hsql jar. The pom.xml is now like this :

<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-api</artifactId>
    <version>20.5</version>
</dependency>
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-shapefile</artifactId>
    <version>20.5</version>
</dependency>
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-swing</artifactId>
    <version>20.5</version>
</dependency>
<dependency>
    <groupId>org.geotools</groupId>
    <artifactId>gt-epsg-hsql</artifactId>
    <version>20.5</version>
</dependency> 

I also updated my code to use org.locationtech.jts.geom.Geometry instead of com.vividsolutions



来源:https://stackoverflow.com/questions/61793283/org-getools-nosuchfielderror-meter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!