无法实例化提供程序org.geotools.reference.factory.epsg.CartesianAuthor



我正在使用maven shade插件将GeoTools包打包到我的uber Jar:中

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>this.is.my.MainClass</mainClass>
</transformer>
</transformers>
<shadedArtifactAttached>false</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>

当JAR在docker-compose环境中构建和运行时,该服务可以工作,但当我在Netbeans中运行该服务时,我会遇到几个异常:

Dec 09, 2020 8:04:53 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated".
java.util.ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.epsg.CartesianAuthorityFactory could not be instantiated
Caused by: java.lang.NoSuchFieldException: UNIT
Dec 09, 2020 8:04:53 AM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "CRSAuthorityFactory". Cause is "ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.wms.AutoCRSFactory could not be instantiated".
java.util.ServiceConfigurationError: org.opengis.referencing.crs.CRSAuthorityFactory: Provider org.geotools.referencing.factory.wms.AutoCRSFactory could not be instantiated
Caused by: java.lang.VerifyError: Bad return type
Exception Details:
Location:
org/geotools/referencing/factory/AuthorityFactoryAdapter.missingFactory(Ljava/lang/Class;Ljava/lang/String;)Lorg/opengis/referencing/FactoryException; @25: areturn
Reason:
Type 'org/opengis/referencing/NoSuchAuthorityCodeException' (current frame, stack[0]) is not assignable to 'org/opengis/referencing/FactoryException' (from method signature)
Current Frame:
bci: @25
flags: { }
locals: { 'org/geotools/referencing/factory/AuthorityFactoryAdapter', 'java/lang/Class', 'java/lang/String' }
stack: { 'org/opengis/referencing/NoSuchAuthorityCodeException' }

等等。

我的pom包含:

<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>24.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>24.0</version>
<type>jar</type>
</dependency>

与GeoTools相关的maven依赖树是:

[INFO] +- org.geotools:gt-referencing:jar:24.0:compile
[INFO] |  +- org.ejml:ejml-ddense:jar:0.34:compile
[INFO] |  |  - org.ejml:ejml-core:jar:0.34:compile
[INFO] |  +- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] |  +- org.geotools:gt-metadata:jar:24.0:compile
[INFO] |  |  +- org.geotools:gt-opengis:jar:24.0:compile
[INFO] |  |  |  - systems.uom:systems-common:jar:2.0.1:compile
[INFO] |  |  |     +- tech.units:indriya:jar:2.0.2:compile
[INFO] |  |  |     |  +- tech.uom.lib:uom-lib-common:jar:2.0:compile
[INFO] |  |  |     |  - javax.inject:javax.inject:jar:1:compile
[INFO] |  |  |     +- si.uom:si-quantity:jar:2.0.1:compile
[INFO] |  |  |     - si.uom:si-units:jar:2.0.1:compile
[INFO] |  |  |        - jakarta.annotation:jakarta.annotation-api:jar:1.3.4:compile
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.8.1:compile
[INFO] |  |  - org.geotools.ogc:net.opengis.ows:jar:24.0:compile
[INFO] |  |     +- org.geotools.ogc:org.w3.xlink:jar:24.0:compile
[INFO] |  |     +- org.eclipse.emf:org.eclipse.emf.common:jar:2.15.0:compile
[INFO] |  |     +- org.eclipse.emf:org.eclipse.emf.ecore:jar:2.15.0:compile
[INFO] |  |     - org.eclipse.emf:org.eclipse.emf.ecore.xmi:jar:2.15.0:compile
[INFO] |  +- it.geosolutions.jgridshift:jgridshift-core:jar:1.3:compile
[INFO] |  +- net.sf.geographiclib:GeographicLib-Java:jar:1.49:compile
[INFO] |  - javax.media:jai_core:jar:1.1.3:compile
[INFO] +- org.geotools:gt-epsg-hsql:jar:24.0:compile
[INFO] |  - org.hsqldb:hsqldb:jar:2.4.1:compile
[INFO] - org.geotools:gt-epsg-extension:jar:24.0:compile

正在执行的代码是:

sourceCRS = CRS.decode("EPSG:4326");

编辑:我忘了说我运行的是Fedora 31,运行的是OpenJDK 11。Netbeans被配置为使用OpenJDK 1.8作为默认平台。这可能是由于类加载器引起的问题?

你知道我做错了什么吗?感谢

您需要提供引用代码的实际实现。来自常见问题解答:

问:如何选择EPSG管理机构

引用模块并没有做太多开箱即用的事情——它需要有人告诉它所有有趣的代码的含义(例如"EPSG:4326"(。

您需要在类路径上选择一个EPSG jar;如果你在类路径上有几个EPSG jar,您将获得FactoryException。

对于大多数需求,只需使用gt-epsg-hsql插件:

  • gt epsgh hsql:将打开包含官方EPSG数据库到一个临时目录,一个很好的桌面解决方案应用程序

有几种替代方案:

  • gt epsg wkt:使用内部属性文件并且是轻量级的而不是官方的和正确的。一个伟大的小程序解决方案

  • gt epsg postgres:使用官方epsg数据库,您必须自己加载到PostgreSQL中。Java EE的出色解决方案应用程序。

  • gt epsg访问:直接使用官方epsg数据库作为分布式。适用于需要最新版本的windows用户的绝佳解决方案官方数据库。

不支持:

  • gt epsg oracle:将官方epsg数据库加载到oracle中使用这个插件

  • gt-epsgh-h2:使用这个流行的纯java数据库

最新更新