gpt4 book ai didi

java - JAI 供应商名称 == null

转载 作者:太空狗 更新时间:2023-10-29 23:01:05 26 4
gpt4 key购买 nike

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

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

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.");

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

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

最佳答案

由于我花了相当多的时间来调试这个问题,我想我应该在这里分享我的解决方案,尽管这个问题已经存在很久了。 Srikanth 的第二个 link特别有帮助。

错误原因

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

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

解决方案

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

Specification-Title: Java Advanced Imaging Image I/O ToolsSpecification-Version: 1.1Specification-Vendor: Sun Microsystems, Inc.Implementation-Title: com.sun.media.imageioImplementation-Version: 1.1Implementation-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

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>

关于java - JAI 供应商名称 == null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7051603/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com