首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JAI ImageRead模块迷路

JAI ImageRead模块迷路
EN

Stack Overflow用户
提问于 2015-02-28 02:58:37
回答 1查看 307关注 0票数 1

我正在尝试编写一个使用GeoTools并读取GeoTiff图像的OSMOSIS扩展。

我写了一个最小的工作示例来说明它的作用:

代码语言:javascript
复制
package that.is.my.test;

import java.io.File;
import java.io.IOException;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.geometry.Envelope2D;
import org.opengis.coverage.grid.GridEnvelope;

public class ExampleClass {
    public static void main(String[] args) {
        new ExampleClass();
    }

    public ExampleClass() {
        try {
            File file = new File("<GEOTIFFFILE>");
            GeoTiffReader reader = new GeoTiffReader(file);
            GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
            GridEnvelope gridBounds = coverage.getGridGeometry().getGridRange();
            System.out.println("grid bounds: " + gridBounds);

            Envelope2D worldBounds = coverage.getEnvelope2D();
            System.out.println("world bounds: " + worldBounds);

            int numBands = coverage.getNumSampleDimensions();
            System.out.println("num bands: " + numBands);

            System.out.println("Goodbye.");
        } catch (IllegalArgumentException | IOException e) {
            e.printStackTrace();
        }
    }
}

注意:这是一个最小的示例类,但是渗透插件中的代码还没有做任何其他的事情。

我可以从NetBeans运行这个示例类,它工作得很好。我可以将它打包到一个可运行的jar中,这也可以很好地工作。

渗透插件不能从NetBeans运行,因为它将被编译到一个jar中,然后被渗透本身调用。但是当我这样做的时候,以GridCoverage2D开头的代码行给出了一个带有消息ImageRead: No OperationDescriptor is registered in the current operation registry under this name.IllegalArgumentException

当我让这两个类打印出一个完整的JAI注册表列表时,我可以看到在渗透的情况下,ImageReadImageWrite和其他几个简单地丢失了。

我就是不明白这是怎么回事!当我查看jars时,文件META-INF\services\javax.imageio.spi.ImageReaderSpi存在于这两个jars中,内容完全相同。

这是我的插件中的POM.xml,示例类具有相同的依赖关系、repos和build指令:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>hello.OSMOSIS</groupId>
    <artifactId>my-osmosis-plugin</artifactId>
    <version>1.0-SNAPSHOT${jarWarning}</version>
    <packaging>jar</packaging>
    <name>OSMOSIS TEST plugin</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <osmosisScope>provided</osmosisScope> <!-- configure this by using the profiles, this is fallback only. -->
        <geotools.version>12-RC1</geotools.version>
    </properties>
    <!-- We define two different profiles: 
        debugWithNetbeans includes all the OSMOSIS jars into the plugin, 
            so that we can test-run the plugin with Netbeans (or anything else). 
            Note: This does not work yet...
        pluginProductions doesn't include the OSMOSIS sources, because later on 
            the plugin will be called BY osmosis and will not need the jars anymore. 
    DO NOT FORGET to set this correctly :-) -->
    <profiles>
        <profile>
            <id>debugWithNetbeans</id>
            <properties>
                <osmosisScope>compile</osmosisScope>
                <jarWarning>-DEBUG-BUILD</jarWarning>
            </properties>
        </profile>
        <profile>
            <id>pluginProduction</id>
            <properties>
                <osmosisScope>provided</osmosisScope>
                <jarWarning></jarWarning>
            </properties>
        </profile>
    </profiles>
    <repositories>
        <repository>
            <id>osgeo</id>
            <name>Open Source Geospatial Foundation Repository</name>
            <url>http://download.osgeo.org/webdav/geotools/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.openstreetmap.osmosis</groupId>
            <artifactId>osmosis-core</artifactId>
            <version>0.43-RELEASE</version>
            <scope>${osmosisScope}</scope>
        </dependency>
        <dependency>
            <groupId>org.openstreetmap.osmosis</groupId>
            <artifactId>osmosis-xml</artifactId>
            <version>0.43.1</version>
            <scope>${osmosisScope}</scope>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geotiff</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-hsql</artifactId>
            <version>${geotools.version}</version>                 
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.3.1</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>hello.OSMOSIS.DoNothingBecauseImAPluginOnly</Main-Class>
                                        <Implementation-Vendor>Blapfi</Implementation-Vendor>
                                        <Implementation-Vendor-Id>huiuiui</Implementation-Vendor-Id>
                                        <Implementation-Version>bapfi</Implementation-Version>
                                    </manifestEntries>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

也许有人能给我一点提示,我哪里做错了?那就太好了。:-)

EN

回答 1

Stack Overflow用户

发布于 2015-03-03 03:19:08

我现在可能找到了一个解释:当JAI jar -或包含JAI的jar -被添加到类路径时,JAI注册表似乎被初始化了。遗憾的是,OSMOSIS的plugins目录中的jars从未添加到任何类路径中,而是由OSMOSIS本身读取。

因此,我的解决方案是将插件构建为一个jar,与一个包含所有依赖项的lib文件夹和一个指示用户将/plugins/lib/*添加到渗透类路径的README捆绑在一起。

osmosis.bat中,这可以通过将-cp "%PLEXUS_CP%"更改为-cp "%PLEXUS_CP%";plugins/lib/*来完成。在linux版本中,我认为你必须使用:而不是; (https://stackoverflow.com/a/219801/4249849)。

Edit1:只有当您当前的工作目录是osmosis/bin时,这才有效。如果你想从任何地方(路径)使用它,你必须添加pushdpopd命令(Windows)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28772330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档