提供程序org.geotools.referencing.factory.epsg.cartesianauthorityfactory

q3aa0525  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(727)

我正在使用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");

编辑:我忘了说我在运行Fedora31和OpenJDK11。netbeans配置为使用OpenJDK1.8作为默认平台。这可能是由于类装入器导致的问题?
知道我做错了什么吗?谢谢

stszievb

stszievb1#

您需要提供引用代码的实际实现。从常见问题:

问:如何选择epsg权威机构?

引用模块并不是很现成的-它需要有人告诉它所有有趣的代码是什么意思(例如“epsg:4326”).
您需要选择一个epsg jar作为类路径的一部分;如果你的类路径上有几个epsg jar,你会得到一个factoryexception。
对于大多数需求,只需使用gt epsg hsql插件即可:
gt epsgh hsql:将包含官方epsg数据库的hsql数据库解压到一个temp目录中,这是一个非常适合桌面应用程序的解决方案。
有几种选择:
gt epsg wkt:使用内部属性文件,是轻量级的,而不是正式的和正确的。一个很好的小程序解决方案
gt epsg postgres:使用官方的epsg数据库,您必须自己加载到postgresql中。一个很好的javaee应用程序解决方案。
gt epsg access:直接使用正式的epsg数据库作为分发。对于需要最新官方数据库的windows用户来说,这是一个很好的解决方案。

不支持:

gt epsg oracle:将官方epsg数据库加载到oracle中以使用此插件
gt-epsgh-h2:使用这个流行的纯java数据库

相关问题