How to configure the maven shade plugin for ImageN?
We have upgraded to geotools 34 which has migrated to this library and see the following error in our application.
java.lang.IllegalArgumentException: ImageRead: No OperationDescriptor is registered in the current operation registry under this name.
at org.eclipse.imagen.ImageN.createNS(ImageN.java:740)
at org.eclipse.imagen.ImageN.create(ImageN.java:672)
at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:760)
at org.opentripplanner.graph_builder.module.ned.GeotiffGridCoverageFactoryImpl.getUninterpolatedGridCoverage(GeotiffGridCoverageFactoryImpl.java:89)
at org.opentripplanner.graph_builder.module.ned.GeotiffGridCoverageFactoryImpl.getGridCoverage(GeotiffGridCoverageFactoryImpl.java:48)
at org.opentripplanner.graph_builder.module.ned.GeotiffGridCoverageFactoryImpl.getGridCoverage(GeotiffGridCoverageFactoryImpl.java:23)
at org.opentripplanner.graph_builder.module.ned.ElevationModule.getThreadSpecificCoverageInterpolator(ElevationModule.java:527)
at org.opentripplanner.graph_builder.module.ned.ElevationModule.processEdge(ElevationModule.java:421)
at org.opentripplanner.graph_builder.module.ned.ElevationModule.processEdgeWithProgress(ElevationModule.java:386)
at org.opentripplanner.graph_builder.module.ned.ElevationModule.buildGraph(ElevationModule.java:230)
at org.opentripplanner.graph_builder.GraphBuilder.run(GraphBuilder.java:211)
at org.opentripplanner.standalone.OTPMain.startOTPServer(OTPMain.java:142)
at org.opentripplanner.standalone.OTPMain.main(OTPMain.java:55)
This happens when using a fat jar with the maven shade plugin. We suspect that we need to update the plugin's configuration to make imagen be packaged correctly.
Currently our plugin configuration looks like this:
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<skip>${skipShadeJar}</skip>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<!-- exclude signatures from merged JAR to avoid invalid signature messages -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.opentripplanner.standalone.OTPMain</Main-Class>
<!-- The ImageIO lines allow some image reader plugins to work
https://stackoverflow.com/questions/7051603/jai-vendorname-null#18495658 -->
<Specification-Title>Java Advanced Imaging Image I/O
Tools
</Specification-Title>
<Specification-Version>1.1</Specification-Version>
<Specification-Vendor>Sun Microsystems, Inc.</Specification-Vendor>
<Implementation-Title>com.sun.media.imageio</Implementation-Title>
<Implementation-Version>1.1</Implementation-Version>
<Implementation-Vendor>Sun Microsystems, Inc.
</Implementation-Vendor>
<Extension-Name>com.sun.media.imageio</Extension-Name>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<id>build-shaded-jar</id>
<goals><goal>shade</goal></goals>
</execution>
</executions>
</plugin>
Can these old Sun values be the cause of the stacktrace? If so, what should we put as the new values?
I found a good configuration here: https://gist.github.com/tkunicki/cdd1f63c54986e9c13a766cf086f93d2
Catching up - your good configuration was:
<transformers>
<!-- merges META-INF/services/ entries instead of overwriting —>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<!-- merges META-INF/javax.media.jai.registryFile.jai entries instead of overwriting —>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/javax.media.jai.registryFile.jai</resource>
</transformer>
<!-- merges META-INF/registryFile.jai entries instead of overwriting —>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/registryFile.jai</resource>
</transformer>
<!-- merges META-INF/registryFile.jaiext entries instead of overwriting —>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/registryFile.jaiext</resource>
</transformer>
Excellent troubleshooting :)
I am re-opening because finding a fix is not the same as fixing the problem for others. To address the problem we need a documentation update to the migration instructions eh?
https://eclipse-imagen.github.io/imagen/migration/
I note that if rename these files to registryFile.jai to registryFile.imagen the shade configuration will need to be updated yet again.
For us it was enough to configure the shade plugin to merge the registryFile.jai files (https://github.com/opentripplanner/OpenTripPlanner/pull/7021) but we only use geotools for reading geotiffs so YMMV.
But yeah, it would have been nice for either the ImageN or geotools docs to mention this. I had to become an expert of how the JAI registry works under a bit of time pressure. Perhaps this confusing experience can be spared for others.
I have included the transformer section in the FAQ of GeoTools. It'll be merged with the upcoming PR that deals with the name change of https://github.com/eclipse-imagen/imagen/pull/121