JAI : how to solve vendorName == null exception
July 24, 2009 1 Comment
Have You ever used JAI (Java Advanced Imaging) ? If You used the class ImageIO in order to read and save images, the answer is yes.
Most of the time, You should not have problem when You deploy Your application with an executable JAR even if You’re using JAI. But, most of the time doesn’t mean never, so that’s a problem !
Recently I had to deploy an application as a JAR, and this application was using quantity of external library. And of course it used JAI.
Well, doing a JAR is not really a problem but …
In my case, the application was developped with Eclipse, and was running fine in it. But, when it comes to run it with a JAR, that was problematic…
I got an exception when a tried to load images, especially TIFF images. This exception was thrown by JAI and told me that the vendorName was null. Interessting : but which vendor ??
The answer is quiet simple : JAI needs sometimes to know the name of the vendor who developped the application, and the implementation of it… OK, you’ll tell me “Fine. It seems it’s my application, so I’m the vendor. But how do I specify that?”. And that’s the point.
When You deploy an application as an executable JAR, You probably know that You need a manifest file. And that manifest file is the key. A complete valid manifest file could be this :
Manifest-Version: 1.0 Main-Class: fr.free.thierrywasyl.myproject.launcher.Launch
But where did I specify the author? No where. But JAI will maybe need to know that, or You’ll get an exception about the vendor. So let’s add some lines, which are good to add (take it as a good practice) which are general:
Manifest-Version: 1.0 Implementation-Vendor: Sun Microsystems, Inc Implementation-Title: Java Runtime Environment Implementation-Version: 1.6.0 Main-Class: fr.free.thierrywasyl.myproject.launcher.Launch
So far so good. So are You a null vendor? Of course not, You get over the exception😉