Forum Stats

  • 3,852,341 Users
  • 2,264,093 Discussions
  • 7,905,035 Comments

Discussions

Erro with JNI & ImageMagick

843829
843829 Member Posts: 49,201
edited Sep 11, 2010 4:30PM in Java Native Interface (JNI)
Hello community.

Sorry for my English, I live in Brazil and my native language is Brazilian Portuguese (pt-br). :-P

I'm trying to use ImageMagick on project in Netbeans. I'm following the tutorial itself JMagick that has the following code: http://sourceforge.net/apps/mediawiki/jmagick/index.php?title=Reading_images

My code is here:
package metadados.exemplos;
import magick.ImageInfo;
import magick.MagickException;
import magick.MagickImage;
public class Readi {
static{
System.out.println(System.getProperty ("java.library.path"));
//        System.setProperty("java.library.path", System.getProperty ("java.library.path")+":/usr/local/lib:/usr/local/include/");
//        System.out.println(System.getProperty ("java.library.path"));
System.loadLibrary("JMagick");
}
public static void main(String[] a) throws MagickException{
//        System.out.println(System.getProperty ("java.library.path"));
//        MagickImage image = new MagickImage(new ImageInfo("/home/paulopatto/Imagens/PATTO/bandeira_brasil.jpg"));
//        System.out.println(image.getImageFormat());
}
}
And when running this code returns me the following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no JMagick in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at univesp.metadados.exemplos.Readi.(Readi.java:12)
Could not find the main class: metadados.exemplos.Readi.  Program will exit.
But as can be seen the the output from System.getProperty ("java.library.path") returns this path:


Vajam And how is my output with the command ls /usr/lib/J*
/usr/lib/JMagick.so
the jar JMagick is in my classpath.

I saw here in the other forum posts about this error but no response or incomplete. I'm using the Ubuntu operating system 10.04 and Java 1.6 (JDK 1.6.0_20 SUN)

Other thing that the load library does not work even with the folder where the JMagick.so is to be part of java.library.path .




Anyone have any suggestions on how to solve this problem?



Thank you atention.

Paulo Patto
web developer
paulopatto gmail [dot] com

Comments

  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    paulopatto wrote:
    But as can be seen the the output from System.getProperty ("java.library.path") returns this path:

    /usr/lib/JMagick.so
    You need the path to the directory not the file.
  • 843829
    843829 Member Posts: 49,201
    Hi Jsschell, thanlk yoy aswer, but this output is comand ls /usr/lib/J*, if past output this command ls /usr/lib/, would have a huge output...
    $ ls /usr/bin/
    alsa-lib                                    libkrb5.so.3.3
    anjuta                                      libkrb5support.so.0
    apache2                                     libkrb5support.so.0.1
    apr-util-1                                  libkresources.so.4
    apt                                         libkresources.so.4.4.0
    aspell                                      libkrosscore.so.4
    at-spi                                      libkrosscore.so.4.4.0
    attica_kde.so                               libkrossui.so.4
    AuErrorDB                                   libkrossui.so.4.4.0
    avahi                                       libktexteditor.so.4
    awk                                         libktexteditor.so.4.4.0
    babl-0.0                                    libktnef.so.4
    blt2.4                                      libktnef.so.4.4.0
    bluetooth                                   libkunitconversion.so
    bonobo                                      libkunitconversion.so.4
    bonobo-activation                           libkunitconversion.so.4.4.0
    brasero                                     libkunittest.so.4
    byobu                                       libkunittest.so.4.4.0
    caca                                        libkutils.so.4
    cgi-bin                                     libkutils.so.4.4.0
    cli                                         libkwalletbackend.so.4
    command-not-found                           libkwalletbackend.so.4.4.0
    compat-ld                                   libkxmlrpcclient.so.4
    compiz                                      libkxmlrpcclient.so.4.4.0
    compizconfig                                liblapack.so.3gf
    ConsoleKit                                  liblapack.so.3gf.0
    couchdb                                     liblaunchpad-integration.so.1
    crda                                        liblaunchpad-integration.so.1.0.0
    crt1.o                                      liblber-2.4.so.2
    crti.o                                      liblber-2.4.so.2.5.4
    crtn.o                                      liblcms.a
    cruft                                       liblcms.la
    cups                                        liblcms.so
    dbus-1.0                                    liblcms.so.1
    debug                                       liblcms.so.1.0.18
    default.sfx                                 libldap-2.4.so.2
    desktopcouch                                libldap_r-2.4.so.2
    directfb-1.2-0                              libldap_r-2.4.so.2.5.4
    dpkg                                        liblirc_client.la
    dri                                         liblirc_client.so.0
    e2initrd_helper                             liblirc_client.so.0.2.1
    eject                                       liblockfile.so.1
    emacsen-common                              liblockfile.so.1.0
    enchant                                     libloginhelper.so.0
    eog                                         libloginhelper.so.0.0.0
    erlang                                      libloudmouth-1.so.0
    esound                                      libloudmouth-1.so.0.1.0
    evince                                      liblpint-bonobo.so.0
    
    and more lines...
    My output for System.out.println(System.getProperty ("java.library.path")); is
    /usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/i386/client:/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
    and JMagick.so is in /usr/lib/


    Again sorr for my english!
  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    Then I would suspect that the name of the library should be

    libJMagick.so
  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    By the way you can use System.load() to load the library explicitly. Provide a complete full file path including the exact name of the library.
  • 843829
    843829 Member Posts: 49,201
    huummm =/

    No. I modify my program for:


    System.loadLibrary("/usr/local/lib/JMagick.so");

    and

    System.loadLibrary("/usr/local/lib/JMagick");

    output of command ls /usr/local/lib:
    [email protected]:~$ ls /usr/local/lib
    jmagick.jar        libMagick++.a           libMagick++.so        libMagickWand.so.3.0.0
    libexiv2.a         libMagickCore.a         libMagick++.so.3      ocaml
    libexiv2.la        libMagickCore.la        libMagick++.so.3.0.0  pkgconfig
    libexiv2.so        libMagickCore.so        libMagickWand.a       python2.6
    libexiv2.so.9      libMagickCore.so.3      libMagickWand.la      site_ruby
    libexiv2.so.9.0.0  libMagickCore.so.3.0.0  libMagickWand.so
    libJMagick.so      libMagick++.la          libMagickWand.so.3
    And I get the error:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Directory separator should not appear in library name: /usr/local/lib/JMagick.so
            at java.lang.Runtime.loadLibrary0(Runtime.java:820)
            at java.lang.System.loadLibrary(System.java:1028)
            at univesp.metadados.exemplos.Readi.<clinit>(Readi.java:14)
    Could not find the main class: univesp.metadados.exemplos.Readi.  Program will exit.
    ='(
  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    paulopatto wrote:
    huummm =/

    No. I modify my program for:


    System.loadLibrary("/usr/local/lib/JMagick.so");

    and

    System.loadLibrary("/usr/local/lib/JMagick");
    Which isn't what I said.

    System.*load*()
  • 843829
    843829 Member Posts: 49,201
    edited Sep 8, 2010 4:49PM
    Friend run!


    Thank you, run with System.load () but why not work with System.loadLibrary?? That should be right. I made a copy of libMagick.so to the folder of the java client:
    paulopatto @ paulopatto-workstation: ~ $ sudo cp Download / magick / JMagick / lib / libJMagick.so / usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/i386/client
    paulopatto @ paulopatto-workstation: ~ $ ls / usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/i386/client
    classes.jsa libJMagick.so libjsig.so libjvm.so Xusage.txt
    paulopatto @ paulopatto-workstation: ~ $
    LoadLibrary but not run, for now I am turning to what I have.



    Thank for you help.

    Edited by: paulopatto on Sep 8, 2010 1:49 PM
  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    paulopatto wrote:
    Thank you, run with System.load () but why not work with System.loadLibrary??
    Because one or both of the following
    - The shared library path is wrong.
    - The 'name' of the library is wrong.
This discussion has been closed.