14

そこで、JAI が TIFF を操作する必要がある TIFF 画像を回転させるアプリケーションのコーディングを終了しました。

Eclipse で作業している場合は正常に動作しますが、ライブラリ用のファット jar を作成し、それを実装するものを作成するたびに ( http://fjep.sourceforge.net/fjeptutorial.htmlごとに)、Java -jar プッシュを実行するとき。 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.
4

7 に答える 7

30

この問題のデバッグにかなりの時間を費やしたので、質問の年齢にもかかわらず、ここで私の解決策を共有すると思いました. Srikanth の 2 番目のリンクは特に役に立ちました。

エラーの理由

JAI は、その深い内部構造の一部、特に低レベル IO のために多くの (すべて?) イメージ リーダーで使用される javax.imageio.spi.IIOServiceProvider にベンダー名を必要とします。文字列が何であるかは気にしませんが、null にすることはできません。

ベンダー名をハードコードするのではなく、ImageReaderSpi クラスは、sun.media.imageioimpl.common.PackageUtil.getVendor() からベンダー名を取得します。これは、jar の MANIFEST.MF から順番に読み取ります。通常、標準の jai-imageio パッケージに対してリンクするため、Sun のベンダー情報が読み取られます。ただし、ファット jar ファイルを作成しているため、Sun の MANIFEST.MF を、必要な情報が不足している独自のものに置き換えました。

解決

MANIFEST.MF ファイルに次の行を含めます。

仕様 - タイトル: Java Advanced Imaging Image I/O Tools
仕様バージョン: 1.1
仕様ベンダー: Sun Microsystems, Inc.
実装タイトル: com.sun.media.imageio
実装バージョン: 1.1
実装ベンダー: Sun Microsystems, Inc.

6 つすべてが定義されている限り、各プロパティの値は何でもかまいません (特定のアプリケーション/バージョン/会社を使用しました)。

メイヴン

maven のアセンブリ プラグインを使用してファット jar を作成していた場合、maven は正しいバージョン番号などを自動的に含めることができます。pom.xml次の<archive>セクションで更新します。

<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>
于 2013-08-28T18:33:39.527 に答える
5

このImageIO jarを使用する必要がありました。それは魅力のように機能しました。ここで見つけました。

于 2011-12-05T13:37:33.110 に答える
2

(Would have been a comment on Quantum7's answer if I had enough reputation)

I ran into the same problem. Quantum7's answer saved the day! After putting in manifestEntries Specification-Vendor and Implementation-Vendor, however, the execution of my fat jar still failed with the exception below. Note it is

version == null!

not

vendorName == null!

java.util.ServiceConfigurationError: javax.imageio.spi.ImageReaderSpi: Provider com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReaderSpi could not be instantiated
        at java.util.ServiceLoader.fail(Unknown Source)
        at java.util.ServiceLoader.access$100(Unknown Source)
        at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source)
        at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
        at java.util.ServiceLoader$1.next(Unknown Source)
        at javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(Unknown Source)
        at javax.imageio.spi.IIORegistry.<init>(Unknown Source)
        at javax.imageio.spi.IIORegistry.getDefaultInstance(Unknown Source)
        at javax.imageio.ImageIO.<clinit>(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: version == null!
        at javax.imageio.spi.IIOServiceProvider.<init>(Unknown Source)
        at javax.imageio.spi.ImageReaderWriterSpi.<init>(Unknown Source)
        at javax.imageio.spi.ImageReaderSpi.<init>(Unknown Source)
        at com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReaderSpi.<init>(CLibJPEGImageReaderSpi.java:80)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        ... 14 more

Putting in manifestEntries below fixed it.

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

When running the fat jar, I made sure that none of the three values in the code below is null.

import com.sun.media.imageioimpl.common.PackageUtil;

public class ManifestCheck {
    public static void main(String[] args) {
        System.out.println(PackageUtil.getVendor());
        System.out.println(PackageUtil.getVersion());
        System.out.println(PackageUtil.getSpecificationTitle());
    }
}
于 2016-07-15T07:02:07.817 に答える
1

これらは、問題の解決に役立ちます。

ソースコードでjai-imageioを実行する方法

vendorName == null

于 2011-08-13T16:11:11.363 に答える