3

I decode a CRS from its EPSG code using:

CoordinateReferenceSystem crs = CRS.decode("EPSG:3035");

This works like a charm, but when the same line of code is executed from an executable *.jar program, the following error occurs:

Exception in thread "main" org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:3035" for authority "EPSG" was found for an object of type "EngineeringCRS".

It seems the EPSG codes can no longer be decoded. This is confirmed by:

System.out.println(CRS.getSupportedAuthorities(true));
System.out.println(CRS.getSupportedCodes("EPSG").size());

which returns

[EPSG, http://www.opengis.net/gml, http://www.opengis.net/def, AUTO2, AUTO, urn:ogc:def, urn:x-ogc:def, CRS]

6741

from the original code, but:

[EPSG, http://www.opengis.net/gml, AUTO2, AUTO, urn:ogc:def, urn:x-ogc:def, CRS, http://www.opengis.net/def]

2

once executed from the *.jar program.

I am stuck for hours with this issue...

Changing the dependency from gt-epsg-hsql to gt-epsg-wkt did not fix the problem. When unzipping the *.jar file, the EPSG database is there, but it seems it cannot be read.

The *.jar program is produced using the maven-assembly-plugin.

2

I missed this section of the FAQ, which describes a proper way to produce an executable *.jar from GeoTools.

Using maven-shade-plugin instead of maven-assembly-plugin fixed the issue. I had in addition to deal with invalid signatures as described here.

This is how the pom.xml looks like in the end:

<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.ManifestResourceTransformer">
                        <manifestEntries>
                            <Main-Class>org.package.MyMainClass</Main-Class>
                        </manifestEntries>
                    </transformer>
                    <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                </transformers>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </execution>
    </executions>
</plugin>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.