Reputation: 506
I'm using the maven-shade-plugin to package GeoTools packages into my 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>
The service works when the JAR is built and run in a docker-compose environment, but when I run the service in Netbeans I get several exceptions:
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' }
And so on.
My pom contains:
<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>
The maven dependency tree related to GeoTools is:
[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
The code being executed is:
sourceCRS = CRS.decode("EPSG:4326");
Edit: I forgot to say that I'm running Fedora 31 running OpenJDK 11. Netbeans is configured to use OpenJDK 1.8 as the default platform. This may be a problem due to class loaders?
Any ideas what I'm doing wrong? Thanks
Upvotes: 0
Views: 1712
Reputation: 10976
You need to provide an actual implementation of the referencing code. From the FAQ:
Q: How to choose an EPSG Authority?
The referencing module does not do very much out of the box - it needs someone to tell it what all the funny codes mean (such as “EPSG:4326”).
You need to choose a single EPSG jar to have on your classpath; if you have several EPSG jars on your classpath you will get a FactoryException.
For most needs just use the gt-epsg-hsql plugin:
- gt-epsgh-hsql: will unpack an HSQL database containing the official EPSG database into a temp directory, a great solution for desktop applications.
There are several alternatives:
gt-epsg-wkt: uses an internal property file and is lightweight rather than official and correct. A great solution for applets
gt-epsg-postgres: uses the official EPSG database which you have to load into PostgreSQL yourself. A great solution for Java EE applications.
gt-epsg-access: directly use an the official EPSG database as distributed. A great solution for windows users that need the latest official database.
Unsupported:
gt-epsg-oracle: Load the official EPSG database into oracle to use this plugin
gt-epsgh-h2: use this popular pure java database
Upvotes: 2