【问题标题】:Raster layer - Geotools: java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO栅格层 - Geotools:java.lang.NoClassDefFoundError:无法初始化类 javax.imageio.ImageIO
【发布时间】:2019-04-05 16:41:04
【问题描述】:

这是我在运行有关依赖项的 mvn 命令时得到的结果。正如我之前解释的主要问题是,当我尝试在 IDE 之外运行 jar 文件时,imageIO lib 不起作用。我想指出,所有其他功能都正常工作。你知道如何解决这个问题吗?我也尝试按照此链接中的步骤操作:http://docs.geotools.org/latest/userguide/build/install/jdk.html 但我得到了同样的错误。

[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] ------------------------------------------------------------------------

这里是 pom.xml 的一部分,它是 maven shade 插件。

          <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>

我得到的新错误如下所示。似乎又缺少与 JAI 库相关的东西。请看:

    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)

【问题讨论】:

  • 那是运行mvn的错误位置,你需要在你的项目文件夹中(里面有pom.xml的那个)
  • 查看GeoTool's FAQ 了解如何构建可执行jar
  • 对不起,这是上一次运行,我设法正确运行 mvn 以及,我有一个可执行的 jar 文件。这个 jar 文件的唯一问题是 javax.imageio 库。你知道如何解决这个问题吗?
  • 你能把这些信息放回你的问题中吗,加上汇编文件和jar文件的内容列表。
  • 请查看更新后的问题。我没有使用 maven 程序集插件,而是使用 maven shade 插件。

标签: maven geotools


【解决方案1】:

您需要将 ImageIO 添加到您的manifestEntries,使用类似:

          <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>   

【讨论】:

  • 非常感谢,第一个问题已经解决了!但是,我再次收到与 JAI lib 相关的新错误。请查看更新后的问题。
  • 您需要提出一个新问题 - 该错误与您的程序有关,而不是与 JAI jars 相关
  • 非常感谢,我会问一个新问题!
【解决方案2】:

你可能还没有构建一个胖罐

如果你只是构建一个jar,依赖是不包括在内的,所以在IDE之外运行jar通常会导致丢失类。

你可以使用maven assembly插件或者maven shade插件来生成fat jar。

【讨论】:

  • 感谢您的回答,我正在使用 maven shade 插件添加依赖项。奇怪的是,除了 imageIO 之外,所有其他依赖项都包含在 jar 中。
  • imageIO的&lt;scope&gt;是什么?
  • 范围是什么意思?如果正确理解您的问题,则需要 imageIO 库才能将光栅层(.tiff 图像)加载到我的应用程序中。
  • 我的意思是 Maven POM 中的范围。运行 mvn dependency:list 并将结果添加到您的问题中。
  • 我只是编辑了我的问题,并发布了关于构建的 pom.xml 的一部分。不幸的是,我无法发布所有 pom.xml 文件。
猜你喜欢
  • 1970-01-01
  • 2023-03-24
  • 2011-01-14
  • 2019-12-14
  • 2021-11-03
  • 2012-08-01
  • 2012-10-10
  • 2015-11-23
  • 2011-09-28
相关资源
最近更新 更多