1 Reply Latest reply on May 14, 2012 4:03 AM by guinotphil

    In JBoss AS 7, got an error of Native Library xxx already loaded in another classloader

    mgao3000

      I am working on migrating an App from JBoss 4.2.3 to JBoss AS 7.1.1.  Now I am facing a problem says "Native Library xxx already loaded in another classloader".

      To be specific: Here are the errors:

      11:22:17,854 ERROR [stderr] (http--127.0.0.1-80-4) Caused by: java.lang.UnsatisfiedLinkError: Native Library E:\programs\jdk1.6.0_29\jre\bin\jpeg.dll already loaded in another classloader
      11:22:17,855 ERROR [stderr] (http--127.0.0.1-80-4)     at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1772)
      11:22:17,856 ERROR [stderr] (http--127.0.0.1-80-4)     at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1724)
      11:22:17,856 ERROR [stderr] (http--127.0.0.1-80-4)     at java.lang.Runtime.loadLibrary0(Runtime.java:823)
      11:22:17,857 ERROR [stderr] (http--127.0.0.1-80-4)     at java.lang.System.loadLibrary(System.java:1028)
      11:22:17,857 ERROR [stderr] (http--127.0.0.1-80-4)     at sun.security.action.LoadLibraryAction.run(Unknown Source)
      11:22:17,858 ERROR [stderr] (http--127.0.0.1-80-4)     at java.security.AccessController.doPrivileged(Native Method)
      11:22:17,859 ERROR [stderr] (http--127.0.0.1-80-4)     at sun.awt.image.codec.JPEGImageDecoderImpl.<clinit>(Unknown Source)
      11:22:17,859 ERROR [stderr] (http--127.0.0.1-80-4)     at com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(Unknown Source)
      11:22:17,860 ERROR [stderr] (http--127.0.0.1-80-4)     at com.sun.media.jai.codecimpl.JPEGImage.<init>(JPEGImageDecoder.java:106)
      11:22:17,861 ERROR [stderr] (http--127.0.0.1-80-4)     at com.sun.media.jai.codecimpl.JPEGImageDecoder.decodeAsRenderedImage(JPEGImageDecoder.java:46)
      11:22:17,862 ERROR [stderr] (http--127.0.0.1-80-4)     at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:88)
      11:22:17,865 ERROR [stderr] (http--127.0.0.1-80-4)     at com.sun.media.jai.opimage.JPEGRIF.create(JPEGRIF.java:43)
      11:22:17,867 ERROR [stderr] (http--127.0.0.1-80-4)     ... 114 more

       

      In the App, we need to load an image (e.g. a jpeg format image) and then customize it (e.g. resize the image). The logic is roughly as the following:

       

      1. get the URL pointing to the image file

      2. get the inputStream of the URL: InputStream imageStream = imageUrl.openStream();

      3. readinputStream into byte array: byte[] imageArray;

      4. ByteArraySeekableStream byteArraySeekableStream = new ByteArraySeekableStream(imageArray);

      5. then do: javax.media.jai.RenderedOp imageRenderedOp = javax.media.jai.JAI.create("stream", byteArraySeekableStream);

       

      somehow, the imageRenderedOp object is not properly created, we get the above exception when trying to do: imageRenderedOp.getHeight();

       

       

      The same App runs well under JBoss 4.2.3.  I am wondering if the error is caused by the Modularized class loading in JBoss AS7?

      Could someone please give us some advices on how to resolve the problem?

      Thanks a lot in advance.

      Regards,

      Michael

        • 1. Re: In JBoss AS 7, got an error of Native Library xxx already loaded in another classloader
          guinotphil

          Hi,

           

          I don't really know about your issue, but here is how I do deploy JAI as modules within my JBoss AS 7 with JDK 6. Hope that helps.

           

          I added the following modules:

           

          javax.media.jai

          <module xmlns="urn:jboss:module:1.1" name="javax.media.jai">

              <dependencies>

                  <module name="com.sun.media.jai" export="true">

                      <exports>

                          <include-set>

                              <path name="javax/media/jai"/>

                              <path name="javax/media/jai/**"/>

                          </include-set>

                      </exports>

                  </module>

              </dependencies>

          </module>

           

           

          javax.imageio.api

          <module xmlns="urn:jboss:module:1.1" name="javax.imageio.api">

              <dependencies>

                  <system export="true">

                      <paths>

                          <path name="javax/imageio"/>

                          <path name="javax/imageio/event"/>

                          <path name="javax/imageio/metadata"/>

                          <path name="javax/imageio/plugins/bmp"/>

                          <path name="javax/imageio/plugins/jpeg"/>

                          <path name="javax/imageio/spi"/>

                          <path name="javax/imageio/stream"/>

                      </paths>

                  </system>

                  <module name="com.sun.media.jai.imageio" services="import"/>

              </dependencies>

          </module>

           

           

          com.sun.media.jai

          <module xmlns="urn:jboss:module:1.1" name="com.sun.media.jai">

              <dependencies>

                  <module name="javax.api"/>

              </dependencies>

           

              <resources>

                  <resource-root path="mlibwrapper-jai-1.1.3.jar"/>

                  <resource-root path="jai-core-1.1.3.jar"/>

                  <resource-root path="jai-codec-1.1.3.jar"/>

                  <!-- Insert resources here -->

              </resources>

          </module>

           

          with native libmlib_jai in lib/linux-i686, lib/linux-x86_64, lib/win-i686 subdirectories of the module.

           

           

           

          com.sun.media.jai.imageio

          <module xmlns="urn:jboss:module:1.1" name="com.sun.media.jai.imageio">

              <dependencies>

                  <module name="javax.api"/>

                  <module name="javax.imageio.api"/>

                  <module name="com.sun.media.jai"/>

              </dependencies>

           

              <resources>

                  <resource-root path="clibwrapper-jiio-1.1.jar"/>

                  <resource-root path="jai-imageio-1.1-evenium.jar"/>

                  <!-- Insert resources here -->

              </resources>

          </module>

           

          with native libclib_jiio in lib/linux-i686, lib/linux-x86_64, lib/win-i686 subdirectories of the module.

           

           

           

          In jboss-deployement-struture, add dependency to

          <module name="javax.media.jai" />

           

          And in the javax.api module, I removed

                          <path name="javax/imageio"/>

                          <path name="javax/imageio/event"/>

                          <path name="javax/imageio/metadata"/>

                          <path name="javax/imageio/plugins/bmp"/>

                          <path name="javax/imageio/plugins/jpeg"/>

                          <path name="javax/imageio/spi"/>

                          <path name="javax/imageio/stream"/>

           

          But added a dependency to

          <module name="javax.imageio.api" export=true />

           

           

           

           

          With this configuration, I never had native lib issue and can use the native codecs. I actually need to run that code within my application to tell the JDK to load the plugins:

           

                  final Class<?> pluginClass;

                  try {

                      pluginClass = Class.forName("com.sun.media.imageioimpl.common.PackageUtil");

                  } catch (ExceptionInInitializerError e) {

                      log.error("Could not register JAI ImageIO plugins", e);

                      return;

                  } catch (ClassNotFoundException e){

                      log.warn("No JAI ImageIO plugins to register", e);

                      return;

                  }

                  final ClassLoader loader = pluginClass.getClassLoader(); // We use impl class loader, as we load from the JAR

           

                  final IIORegistry serviceRegistery = IIORegistry.getDefaultInstance();

                  final Iterator<Class<?>> categories = serviceRegistery.getCategories();

           

                  while (categories.hasNext()) {

                      final Class<?> c = categories.next();

                      @SuppressWarnings("unchecked")

                   final Iterator<IIOServiceProvider> riter = (Iterator<IIOServiceProvider>) sun.misc.Service.providers(c, loader);

           

                      while (riter.hasNext()) {

                          serviceRegistery.registerServiceProvider(riter.next());

                      }

                 }