0

I am trying to register for a servlet the following and getting an exception. The code is:

static {
        IIORegistry registry = IIORegistry.getDefaultInstance();
        registry.registerServiceProvider(new com.twelvemonkeys.servlet.image.IIOProviderContextListener());
        registry.registerServiceProvider(new com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi());
        registry.registerServiceProvider(new com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterSpi());
    }

I am getting the following exception thrown. Funny thing is I only am using the read not the write. I am using the 3.6 version of twelvemonkeys.

Thanks for any hints!

Exception in thread "main" java.lang.NoSuchMethodError: com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName(Ljavax/imageio/spi/ServiceRegistry;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterSpi.onRegistration(JPEGImageWriterSpi.java:82)
    at javax.imageio.spi.SubRegistry.registerServiceProvider(Unknown Source)
    at javax.imageio.spi.ServiceRegistry.registerServiceProvider(Unknown Source)
    at javax.imageio.spi.IIORegistry$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.imageio.spi.IIORegistry.registerInstalledProviders(Unknown Source)
    at javax.imageio.spi.IIORegistry.registerStandardSpis(Unknown Source)
    at javax.imageio.spi.IIORegistry.<init>(Unknown Source)
    at javax.imageio.spi.IIORegistry.getDefaultInstance(Unknown Source)
    at deeplearningtest.test.<clinit>(test.java:32)
F.Lazarescu
  • 1,385
  • 2
  • 16
  • 31
Tony Anecito
  • 347
  • 2
  • 13
  • The `IIOProviderContextListener` is a *web context listener* (it's not a service provider), so you need to register it in the web context (typically using `web.xml`). And if you make it work, you should not need the "manual" `registry.registerServiceProvider` invocations at all. The exception indicates that you are missing the TwelveMonkeys `imageio-core-3.6.jar`. – Harald K Nov 03 '20 at 08:09
  • Thanks haraldK. I already have that imageio-core-3.6.jar included in the project. If I remove the "manual" piece of code I still get that error. I am running the project in eclipse outside of the servlet context to troubleshoot an error I get when running the code inside of a servlet. I switched away from using the old twelvemonkeys 3.4 snapshot since I am using the beta7 of Deeplearning. – Tony Anecito Nov 03 '20 at 17:52
  • Looking closely at the exception it indicates for the ImageIO.read() call that I do it is looking for that to be registered. Now that class is from javax.image.ImageIO. I am using it to read in a image file into a BufferedImage variable. If there is a better approved way for that for use with that with Deeplearning4j I am all ears. Many Thanks! – Tony Anecito Nov 03 '20 at 18:52
  • So, based on the exception and the answer below, most likely there was a version mismatch between one or more JAR files. Key point: Always stick to a single version for all JARs! :-) – Harald K Nov 04 '20 at 08:03
  • As I mentioned all names for those jars are the same. The rest of the jars from from other projects for Deeplearning4J have have the versions in the name. This appears to be a recent change for the above so I strongly suggest that be reversed. – Tony Anecito Nov 04 '20 at 16:40
  • Where did you find the JARs without versions in the file name? The ones listed on the [home page](https://github.com/haraldk/TwelveMonkeys#links-to-prebuilt-binaries) are all *with* version. The same with the ones from [Maven Central](https://search.maven.org/search?q=g:com.twelvemonkeys.imageio%20AND%20v:3.6). If you got the non-versioned JARs from Deeplearning4J, please file a ticket in their issue tracker. PS: You can also find the version information inside the JAR. – Harald K Nov 04 '20 at 16:50
  • From Maven Central. But they had different file sizes for the same name. So I was wrong about the file name. Not sure why I got different file sizes for the same file name which indicated either transmission error or different versions for the same name. The change from TwelveMonkeys is what threw me off. That link to your list of new names is what helped. – Tony Anecito Nov 04 '20 at 17:56
  • 1
    Ok HaraldK I agree with everything you have said. I was working a 16hr day and should have stopped after 12 hours. :-) – Tony Anecito Nov 05 '20 at 01:19
  • Ok HaraldK I followed your advice regarding jars and had to add the javax-servlet-api-.1.4.0.jar from Maven and I now get the exception: java.lang.ClassNotFoundException: javax.imageio.spi.ServiceRegistry$Filter not sure how to fix that yet but will try later today/evening. Again many thanks for your help! – Tony Anecito Nov 05 '20 at 12:13

1 Answers1

0

Ok, I solved the problem. I went to https://github.com/haraldk/TwelveMonkeys#manual-dependency-example and I re-downloaded all the jars mentioned in the article making sure I paid close attention to the versions to make sure 3.6 was selected since 3.6 is not shown as part of the jar name (which I liked). Once I restarted eclipse I got past that problem. Many thanks haraldK!

Tony Anecito
  • 347
  • 2
  • 13