Cannot got JMagick working

4.7k Views Asked by At

I have strange problem with JMagick library. I use Debian, so I have installed libjmagick6-java and libjmagick6-jni, and here are steps I have done:

  • I have copied jmagick-6.6.9.jar from /usr/share/java/ to $JAVA_HOME/jre/lib/ext/.
  • I have set /usr/lib/jni (where is libJMagick.so) as native library location in:
    • JRE System library (in eclipse)
    • jmagick-6.6.9.jar (in eclipse)

Also I have tested JMagick in simple Java project and there it works, but in the second project which is web application running in Tomcat 6, it just doesn't work..

Here is my code which WORKS - so jmagick must be installed right:

public class Main {
    public static void main(String[] arg) {
        MagickImage image = null;
        ImageInfo imageInfo = null;

        try {
            imageInfo = new ImageInfo("/home/firzen/IMG_0120.JPG");
            image = new MagickImage(imageInfo);
            System.out.println(image.getDimension().width);
        } catch (MagickException e) {
                System.out.println(e);
        }
        image.destroyImages();
    }
}

And here is the code in webapp which is NOT WORKING:

public void init() {        
    ServletContext sc = getServletContext();
    cacheHandlers = (Map<String, CacheContext>) sc.getAttribute("handlers");
    Boolean applicationReady = (Boolean) sc.getAttribute("ready");
    isReady = cacheHandlers != null && Boolean.TRUE.equals(applicationReady);

    System.out.println("zde");
    MagickImage image = null;
    ImageInfo imageInfo = null;

    try {
        imageInfo = new ImageInfo("/home/firzen/IMG_0120.JPG");
        image = new MagickImage(imageInfo);
        System.out.println(image.getDimension().width);
    } catch (MagickException e) {
            System.out.println(e);
    }
    image.destroyImages();
}

Finally here is the exception thrown by mentioned code:

java.lang.UnsatisfiedLinkError: no JMagick in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at magick.Magick.<clinit>(Magick.java:18)
    at cz.bach.mrimage.MrImageSrv.init(MrImageSrv.java:44)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

Please tell me some ideas how to solve this problem.. Thanks in advance!

1

There are 1 best solutions below

1
On BEST ANSWER

I have finally solved this problem by checking the real java.library.path with:

System.out.println("java.library.path is: " + System.getProperty("java.library.path"));

This gave me this mess:

java.library.path is: /opt/jdk1.7.0_45/jre/lib/i386/server:/opt/jdk1.7.0_45/jre/lib/i386:/opt/jdk1.7.0_45/jre/../lib/i386:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386::/usr/java/packages/lib/i386:/lib:/usr/lib

At the end you can see /usr/lib, so I have created link to libJMagick.so in /usr/lib by:

ln -s /usr/lib/jni/libJMagick.so /usr/lib/libJMagick.so

Enjoy! :-)