JAI vendorname == null [英] JAI vendorname == null

查看:162
本文介绍了JAI vendorname == null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我完成了我的应用程序编码以旋转TIFF图像,这需要JAI来操纵TIFF。

So I finished coding my application to rotate TIFF images which required JAI to manipulate the TIFFs.

在Eclipse下工作时它工作正常,但每当我为库构建一个胖jar然后创建一个实现它的时候(每 http://fjep.sourceforge.net/fjeptutorial.html ),当我做java -jar Push.jar \ path \ to \dir,它一直运行直到它到达压缩和保存的部分:

It works fine when working under Eclipse, but whenever I build a fat jar for the library and then create one implementing that (per http://fjep.sourceforge.net/fjeptutorial.html), when I do the java -jar Push.jar \path\to\dir, it runs up until it hits the part where it is compressing and saving:

TIFFImageWriterSpi tiffspi = new TIFFImageWriterSpi();
ImageWriter writer = tiffspi.createWriterInstance();
//Iterator<ImageWriter> iter =  ImageIO.getImageWritersByFormatName("TIFF");
//ImageWriter writer = iter.next();

ImageWriteParam param2 = writer.getDefaultWriteParam();
param2.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);

param2.setCompressionType("LZW");
param2.setCompressionQuality(0.0f);
File fOutputFile = workArea[i];
ImageOutputStream ios = ImageIO.createImageOutputStream(fOutputFile);
writer.setOutput(ios);

if (frontPage == 1)
{
     writer.write(null, new IIOImage(pg1, null, null), param2);
     writer.writeInsert(-1, new IIOImage(pg2, null, null), param2);
}
else if (frontPage == 2)
{
     writer.write(null, new IIOImage(pg2, null, null), param2);
     writer.writeInsert(-1, new IIOImage(pg1, null, null), param2);
}

remaining = remaining - 1;
    if (remaining > 0)
     System.out.println(remaining + " remaining.");
else
     System.out.println("Done.");

它在该部分的第一行显示消息:

It blows up on the first line of that section with the message:

 Exception in thread "main" java.lang.IllegalArgumentException: vendorName == null!
 ....rest of stack trace.


推荐答案

因为我花了相当多的时间来调试这个问题,我想我会在这里分享我的解决方案,尽管问题的年龄。 Srikanth的第二个链接特别有帮助。

Since I spent a considerable amount of time debugging this problem, I thought I would share my solution here, despite the age of the question. Srikanth's second link was particularly helpful.

JAI需要一些供应商名称的深层内部,尤其是javax.imageio.spi.IIOServiceProvider,它被许多(所有?)图像阅读器使用他们的低级别IO。字符串是什么并不挑剔,但它不能为空。

JAI requires a vendor name for some of its deep internals, particularly the javax.imageio.spi.IIOServiceProvider which gets used by many (all?) of the image readers for their low-level IO. It's not picky what the string is, but it can't be null.

ImageReaderSpi类不是硬编码供应商名称,而是从sun获取供应商名称。 media.imageioimpl.common.PackageUtil.getVendor()。这反过来从jar的MANIFEST.MF 中读取它。通常,您会链接到标准的jai-imageio包,因此Sun的供应商信息会被读取。但是,由于您正在创建一个胖文件,因此您将Sun的MANIFEST.MF替换为您自己的,缺少所需信息。

Rather than hard-code the vendor name, the ImageReaderSpi class gets the vendor name from sun.media.imageioimpl.common.PackageUtil.getVendor(). This in turn reads it from the jar's MANIFEST.MF. Normally you link against the standard jai-imageio packagage, so Sun's vendor info gets read. However, since you're making a fat jar file, you replaced Sun's MANIFEST.MF with your own which lacks the required information.

在MANIFEST.MF文件中包含以下行:

Include the following lines in your MANIFEST.MF file:


Specification-Title: Java Advanced Imaging Image I/O Tools
Specification-Version: 1.1
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: com.sun.media.imageio
Implementation-Version: 1.1
Implementation-Vendor: Sun Microsystems, Inc.

每个属性的值可以是任何值(我使用我的特定应用程序/版本/公司),只要定义了所有六个。

The values for each property can be anything (I used my specific application/version/company), as long as all six are defined.

如果你使用maven的程序集插件来创建你的胖子jar,maven可以自动包含正确的版本号等。使用以下< archive> 部分更新 pom.xml

If you were using maven's assembly plugin to create your fat jar, maven can automatically include the correct version numbers and such. Update your pom.xml with the following <archive> section:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
            </manifest>
            <manifestEntries>
                <Specification-Vendor>MyCompany</Specification-Vendor>
                <Implementation-Vendor>MyCompany</Implementation-Vendor>
            </manifestEntries>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>create-my-bundle</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

这篇关于JAI vendorname == null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆