Exception when trying to save images

瘦欲@ 提交于 2019-12-01 12:09:17
Codey McCodeface

As @Victor says I think you should look at

Exception in thread "main" sun.misc.ServiceConfigurationError: 
javax.imageio.spi.ImageWriterSpi: 
Provider com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageWriterSpi 
could not be instantiated: java.lang.IllegalArgumentException: vendorName == null!

I had this issue just yesterday and it was tricky. There are similar questions here. I found if I included jai_imageio in the jar and did not modify the manifest file to include the contents of the JAI manifest file or combine the files in the services folder of META-INF in your build then I had a number of errors similar to yours. My application did work though without JAI included since JAI was installed locally I opted to build it with JAI included for the time being.

Opening you jar you will find a directory called META-INF. In there is the file MANIFEST.MF. I use Maven to include the JAI things in the Manifest file so it looks like

Manifest-Version: 1.0
Implementation-Title: com.sun.media.imageio
Implementation-Version: 1.0_01
Built-By: myName
Specification-Vendor: Sun Microsystems, Inc.
Created-By: Apache Maven
Implementation-Vendor: Sun Microsystems, Inc.
Build-Jdk: 1.6.0_43
Specification-Title: Java Advanced Imaging Image I/O Tools
Specification-Version: 1.0-mr
Extension-Name: com.sun.media.imageio
Main-Class: myMain
Archiver-Version: Plexus Archiver

You should have your name and your main class substituted in there. You could just modify this file and jar it up yourself on the command line if you don't use Maven (or Ant) to get it working. I had the extra issue where some of my included jars were overwritting files in the services folder of META-INF. Instead I merged these files using Maven's Shade plugin.

Jefferson Ferregato

add this lines into build.xml (solved for me)

<manifest>
    <attribute name="Main-Class" value="${main.class}"/>
    <attribute name="Built-By" value="${user.name}" />
    <attribute name="Built-Date" value="${TODAY}" />                   
    <attribute name="Implementation-Title" value="MyApp" />
    <attribute name="Implementation-Vendor" value="MyCompany" />                
    <attribute name="Implementation-Version" value="${version.num}-b${build.number}"/>                              
</manifest>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!