Elena Valari
Elena Valari

Reputation: 343

Raster layer - Geotools: java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO

Here is what i got back when i run the mvn command regarding the dependencies. The main problem as i explained before is that the imageIO lib is not working when i am trying to run the jar file outside IDE. I would like to point out that all the other functionalities are working properly. Do you have any idea of how to solve this problem? I have also try to follow the steps in this link: http://docs.geotools.org/latest/userguide/build/install/jdk.html but i got back the same error.

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gisLaraMaven gis
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.geotools:gt-wfs:jar:20.1 is missing, no dependency information available
[INFO]
[INFO] --- maven-dependency-plugin:2.1:list (default-cli) @ gis ---
[INFO]
[INFO] The following files have been resolved:
[INFO]    com.conversantmedia:disruptor:jar:1.2.13:compile
[INFO]    com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO]    com.google.errorprone:error_prone_annotations:jar:2.2.0:compile
[INFO]    com.google.guava:failureaccess:jar:1.0:compile
[INFO]    com.google.guava:guava:jar:27.0-jre:compile
[INFO]    com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO]    com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO]    com.miglayout:miglayout:jar:swing:3.7:compile
[INFO]    com.vividsolutions:jts:jar:1.13:compile
[INFO]    commons-codec:commons-codec:jar:1.2:compile
[INFO]    commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO]    commons-io:commons-io:jar:2.6:compile
[INFO]    commons-logging:commons-logging:jar:1.0.4:compile
[INFO]    commons-pool:commons-pool:jar:1.5.4:compile
[INFO]    hsqldb:hsqldb:jar:1.8.0.7:compile
[INFO]    it.geosolutions.imageio-ext:imageio-ext-geocore:jar:1.1.27:compile
[INFO]    it.geosolutions.imageio-ext:imageio-ext-streams:jar:1.1.27:compile
[INFO]    it.geosolutions.imageio-ext:imageio-ext-tiff:jar:1.1.27:compile
[INFO]    it.geosolutions.imageio-ext:imageio-ext-utilities:jar:1.1.27:compile
[INFO]    it.geosolutions.jaiext.affine:jt-affine:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.algebra:jt-algebra:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.bandcombine:jt-bandcombine:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.bandmerge:jt-bandmerge:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.bandselect:jt-bandselect:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.binarize:jt-binarize:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.border:jt-border:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.buffer:jt-buffer:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.classifier:jt-classifier:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.colorconvert:jt-colorconvert:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.colorindexer:jt-colorindexer:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.crop:jt-crop:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.errordiffusion:jt-errordiffusion:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.format:jt-format:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.imagefunction:jt-imagefunction:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.iterators:jt-iterators:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.lookup:jt-lookup:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.mosaic:jt-mosaic:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.nullop:jt-nullop:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.orderdither:jt-orderdither:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.piecewise:jt-piecewise:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.rescale:jt-rescale:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.rlookup:jt-rlookup:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.scale:jt-scale:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.scale2:jt-scale2:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.shadedrelief:jt-shadedrelief:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.stats:jt-stats:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.translate:jt-translate:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.utilities:jt-utilities:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.vectorbin:jt-vectorbin:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.warp:jt-warp:jar:1.1.3:compile
[INFO]    it.geosolutions.jaiext.zonal:jt-zonal:jar:1.1.3:compile
[INFO]    javax.measure:unit-api:jar:1.0:compile
[INFO]    javax.media:jai_codec:jar:1.1.3:compile
[INFO]    javax.media:jai_core:jar:1.1.3:compile
[INFO]    javax.media:jai_imageio:jar:1.1:compile
[INFO]    jgridshift:jgridshift:jar:1.0:compile
[INFO]    junit:junit:jar:3.8.1:test
[INFO]    net.sf.geographiclib:GeographicLib-Java:jar:1.49:compile
[INFO]    org.apache.xml:xml-commons-resolver:jar:1.2:compile
[INFO]    org.checkerframework:checker-qual:jar:2.5.2:compile
[INFO]    org.codehaus.mojo:animal-sniffer-annotations:jar:1.17:compile
[INFO]    org.ejml:ejml-core:jar:0.34:compile
[INFO]    org.ejml:ejml-ddense:jar:0.34:compile
[INFO]    org.geotools:gt-api:jar:20.1:compile
[INFO]    org.geotools:gt-coverage:jar:20.1:compile
[INFO]    org.geotools:gt-cql:jar:20.1:compile
[INFO]    org.geotools:gt-data:jar:20.1:compile
[INFO]    org.geotools:gt-epsg-hsql:jar:20.1:compile
[INFO]    org.geotools:gt-geotiff:jar:20.1:compile
[INFO]    org.geotools:gt-image:jar:20.1:compile
[INFO]    org.geotools:gt-main:jar:20.1:compile
[INFO]    org.geotools:gt-metadata:jar:20.1:compile
[INFO]    org.geotools:gt-opengis:jar:20.1:compile
[INFO]    org.geotools:gt-process:jar:20.1:compile
[INFO]    org.geotools:gt-referencing:jar:20.1:compile
[INFO]    org.geotools:gt-render:jar:20.1:compile
[INFO]    org.geotools:gt-shapefile:jar:20.1:compile
[INFO]    org.geotools:gt-swing:jar:20.1:compile
[INFO]    org.geotools:gt-wfs:jar:20.1:compile
[INFO]    org.geotools:gt-wms:jar:20.1:compile
[INFO]    org.geotools:gt-xml:jar:20.1:compile
[INFO]    org.hsqldb:hsqldb:jar:2.4.1:compile
[INFO]    org.jaitools:jt-utils:jar:1.5.0:compile
[INFO]    org.jaitools:jt-zonalstats:jar:1.5.0:compile
[INFO]    org.jdom:jdom2:jar:2.0.6:compile
[INFO]    org.locationtech.jts:jts-core:jar:1.16.0:compile
[INFO]    org.postgresql:postgresql:jar:9.4-1202-jdbc42:compile
[INFO]    org.slf4j:slf4j-api:jar:1.7.13:compile
[INFO]    si.uom:si-quantity:jar:0.7.1:compile
[INFO]    si.uom:si-units-java8:jar:0.7.1:compile
[INFO]    systems.uom:systems-common-java8:jar:0.7.2:compile
[INFO]    tec.uom:uom-se:jar:1.0.8:compile
[INFO]    tec.uom.lib:uom-lib-common:jar:1.0.2:compile
[INFO]    xerces:xercesImpl:jar:2.11.0:compile
[INFO]    xml-apis:xml-apis:jar:1.4.01:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.701s
[INFO] Finished at: Wed Apr 03 18:37:35 EEST 2019
[INFO] Final Memory: 12M/243M
[INFO] ------------------------------------------------------------------------

And here is the part of the pom.xml which is the maven shade plugin.

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <!-- This bit sets the main class for
the executable jar as you otherwise -->
                                <!-- would with the assembly plugin
                                   -->
                                <transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>

<Main-Class>com.mycompany.gislaramaven.gisMap_3</Main-Class>
                                    </manifestEntries>
                                </transformer>
                                <!-- This bit merges the various
GeoTools META-INF/services files         -->
                                <transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                             <archive>
            <manifest>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
            </manifest>
            <manifestEntries>
                <Specification-Vendor>Sun Microsystems, Inc</Specification-Vendor>
                <Implementation-Vendor>Sun Microsystems, Inc</Implementation-Vendor>
            </manifestEntries>
        </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

The new error that i am getting back is given below. It seems that again something is missing related to the JAI lib. Please have a look:

    WARNING  The input argument(s) may not be null.
java.lang.IllegalArgumentException: The input argument(s) may not be null.
        at javax.media.jai.ParameterBlockJAI.getDefaultMode(ParameterBlockJAI.java:136)
        at javax.media.jai.ParameterBlockJAI.<init>(ParameterBlockJAI.java:157)
        at javax.media.jai.ParameterBlockJAI.<init>(ParameterBlockJAI.java:178)
        at it.geosolutions.jaiext.vectorbin.ROIGeometry.getAsImage(ROIGeometry.java:473)
        at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.addRoiIfMissing(GridCoverageRenderer.java:1095)
        at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.reproject(GridCoverageRenderer.java:509)
        at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.renderImage(GridCoverageRenderer.java:958)
        at org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.paint(GridCoverageRenderer.java:1279)
        at org.geotools.renderer.lite.StreamingRenderer$RenderCoverageReaderRequest.execute(StreamingRenderer.java:3650)
        at org.geotools.renderer.lite.StreamingRenderer$PainterThread.run(StreamingRenderer.java:3744)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

Upvotes: 0

Views: 2522

Answers (2)

Ian Turton
Ian Turton

Reputation: 10976

You need to add ImageIO to your manifestEntries using something like:

          <transformers>                                                    
            <!-- This bit sets the main class for the executable jar as you otherwise -->
            <!-- would with the assembly plugin -->                         
            <transformer                                                    
              implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <manifestEntries>                                             
                <Main-Class>com.ianturton.tileviewer.TileViewer</Main-Class>
                <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>
              </manifestEntries>                                            
            </transformer>                                                  
            <!-- This bit merges the various GeoTools META-INF/services files -->
            <transformer                                                    
              implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
          </transformers>   

Upvotes: 0

J Fabian Meier
J Fabian Meier

Reputation: 35785

You probably have not build a fat jar.

If you just build a jar, dependencies are not included, so running the jar outside the IDE will usually result in missing classes.

You can use the maven assembly plugin or maven shade plugin to generate a fat jar.

Upvotes: 0

Related Questions