JVM and shared libraries

Discussion in 'Java' started by Dave Neary, Jun 9, 2004.

  1. Dave Neary

    Dave Neary Guest

    Hi all,

    I have a Java applet which uses some JNI stuff to interract with a scanner.

    The basic way things are is:

    java -> call sane stuff
    sane.jar -> loadLibrary(sanej)
    sanej.dll contains the jni wrapper stuff around sane.dll

    On windows, sanej.dll is in jre/bin, and sane.dll is on the system PATH
    (in c:\sane). On linux, libsanej.so is in jre/lib/i386, and libsane.so is
    in /usr/local/lib, which is in the system ld.so search path.

    When I run the applet as an application (calling the constructor, init,
    start, etc manually in the main method) all goes well, I get a scan.

    When I load the applet in a browser on Windows, however, it all goes
    pear-shaped and the browser dies without a trace.

    On Linux, the same applet works fine.

    The questions, then, are
    1) How can I get more information about what's going wrong on windows?
    I assume that the problem is that sane.dll isn't being found when a
    function in the library is called. What search mechanism will be used to
    search for sane.dll? I have also tried putting sane.dll in jre/bin,
    without success.

    2) Anyone know how to fix it and make everything better? :)

    Thanks a lot,
    Dave.
     
    Dave Neary, Jun 9, 2004
    #1
    1. Advertising

  2. Dave Neary

    Roedy Green Guest

    On 09 Jun 2004 17:13:02 GMT, Dave Neary <>
    wrote or quoted :

    >When I load the applet in a browser on Windows, however, it all goes
    >pear-shaped and the browser dies without a trace.


    I hope your Applet was signed, required to use JNI.

    Try using load instead of loadlibrary. Your path may not be what you
    think.

    Use Wassup to find out what your path really is when you are in the
    browser.

    See http://mindprod.com/wassup.html

    Then make sure your dll in on THAT path.

    This sort of thing can drive you round the bend.

    Consider Java Web Start which automatically installs your dlls on the
    path.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 9, 2004
    #2
    1. Advertising

  3. Dave Neary

    ALR Guest

    Hi Dave

    You can try to open the java console (option somewhere in the browser's
    menu ), so the stack trace (if any) could be printed.
    You can also write some additional stuff to start your application in a
    frame (your application could be run in the browser or outside)
    and start java.exe in a C debugger to debug your dll by setting some
    parameters in the command line of your debugger.

    Regards
    Alain

    "Dave Neary" <> a écrit dans le message de news:
    ldomain...
    > Hi all,
    >
    > I have a Java applet which uses some JNI stuff to interract with a

    scanner.
    >
    > The basic way things are is:
    >
    > java -> call sane stuff
    > sane.jar -> loadLibrary(sanej)
    > sanej.dll contains the jni wrapper stuff around sane.dll
    >
    > On windows, sanej.dll is in jre/bin, and sane.dll is on the system PATH
    > (in c:\sane). On linux, libsanej.so is in jre/lib/i386, and libsane.so is
    > in /usr/local/lib, which is in the system ld.so search path.
    >
    > When I run the applet as an application (calling the constructor, init,
    > start, etc manually in the main method) all goes well, I get a scan.
    >
    > When I load the applet in a browser on Windows, however, it all goes
    > pear-shaped and the browser dies without a trace.
    >
    > On Linux, the same applet works fine.
    >
    > The questions, then, are
    > 1) How can I get more information about what's going wrong on windows?
    > I assume that the problem is that sane.dll isn't being found when a
    > function in the library is called. What search mechanism will be used to
    > search for sane.dll? I have also tried putting sane.dll in jre/bin,
    > without success.
    >
    > 2) Anyone know how to fix it and make everything better? :)
    >
    > Thanks a lot,
    > Dave.
    >
     
    ALR, Jun 9, 2004
    #3
  4. Dave Neary

    Dave Neary Guest

    Hi,

    In article <40c77752$0$17194$>, ALR wrote:
    > You can try to open the java console (option somewhere in the browser's
    > menu ), so the stack trace (if any) could be printed.


    Thanks for the tip. As I said, though, the browser and the jvm crash and
    burn completely on the error. There is no stack trace to view, because
    the java console window disappears on me.

    > You can also write some additional stuff to start your application in a
    > frame (your application could be run in the browser or outside)
    > and start java.exe in a C debugger to debug your dll by setting some
    > parameters in the command line of your debugger.


    I have added lots of traces to my code, so I know that the problem occurs
    when the native method is called. I'm not sure where in that method the
    problem is though.

    And as I said, when I run it as an application, there is no problem.

    Thanks for your tips, though.

    Cheers,
    Dave.
     
    Dave Neary, Jun 10, 2004
    #4
  5. Dave Neary

    Dave Neary Guest

    Hi Roedy,

    In article <>, Roedy Green wrote:
    > I hope your Applet was signed, required to use JNI.


    It is indeed.

    > Try using load instead of loadlibrary. Your path may not be what you
    > think.
    >
    > Use Wassup to find out what your path really is when you are in the
    > browser.


    Indeed, jre/bin was not on the path, and java.library.path gets the system
    path. I moved the dlls all into the one directory, on the path, but the
    results were identical.

    > This sort of thing can drive you round the bend.


    Tell me about it :)

    > Consider Java Web Start which automatically installs your dlls on the
    > path.


    Unfortunately, this is a client constraint (*must* be web, *must* look
    like a normal web page) - the applet is in the page header, and provides
    an API for its actions which get called by javascript on the buttons in
    the page.


    Thanks for the help,
    Dave.
     
    Dave Neary, Jun 10, 2004
    #5
  6. Dave Neary

    Roedy Green Guest

    On 10 Jun 2004 13:54:30 GMT, Dave Neary <>
    wrote or quoted :

    >Indeed, jre/bin was not on the path, and java.library.path gets the system
    >path. I moved the dlls all into the one directory, on the path, but the
    >results were identical.


    You have a nightmare here. You have no control over how each user
    sets up his path or how every browser on earth does it. You have to
    get that dll somewhere on HIS path.

    Check the path. There should be no ;; in it.

    I found further that Netscape insisted the DLL be installed BEFORE
    Netscape even started or it would not recognise it.

    I went through this with Setclock and eventually gave up and turned it
    into a JWS application. See http://mindprod.com/jgloss/setclock.html

    I'd say your best bet is to put the dll in some standard place and use
    load rather than loadlibrary to find it.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 10, 2004
    #6
  7. Dave Neary

    Roedy Green Guest

    On Thu, 10 Jun 2004 14:10:22 GMT, Roedy Green
    <> wrote or quoted :

    >
    >I found further that Netscape insisted the DLL be installed BEFORE
    >Netscape even started or it would not recognise it.


    Java should be fixed so that load also looks in the jar for the DLL.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 10, 2004
    #7
  8. Dave Neary

    alr Guest

    Hi
    If you want to live dangerously you can try to run IE in the debugger, as
    the jvm is an activex, I think it should work...

    > And as I said, when I run it as an application, there is no problem.
     
    alr, Jun 10, 2004
    #8
  9. Dave Neary

    Dave Neary Guest

    Hi,

    In article <>, Roedy Green wrote:
    > You have a nightmare here. You have no control over how each user
    > sets up his path or how every browser on earth does it. You have to
    > get that dll somewhere on HIS path.


    I caught a break on this, I found a hs_err_pidXXXX.log file (god knows why
    I didn't see them earlier, there is a bunch of them) which gives me the
    answer to why IExplorer crashes.

    The dlls with the JNI bindings are installed and found fine, as is
    sane.dll. The problem is in cygwin1.dll/ Here's the first few lines of the
    log file I mentioned above:

    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at
    PC=0x61044A01
    Function=getservbyname+0xC1
    Library=c:\sane\cygwin1.dll

    Current Java thread:
    at org.sane.Sane.getNumberOfDevices(Native Method)
    at com.phenix.framework.scan.ScanApplet.init(ScanApplet.java:227)
    at sun.applet.AppletPanel.run(AppletPanel.java:353)
    at java.lang.Thread.run(Thread.java:534)

    Does this mean that cygwin1.dll doesn't have the necessary permissions to
    make the system call, or that there is a bug in cygwin? As I said before,
    as an application, this works fine.

    Cheers,
    Dave.
     
    Dave Neary, Jun 11, 2004
    #9
  10. On 11 Jun 2004 13:36:09 GMT, Dave Neary wrote:
    > An unexpected exception has been detected in native code outside the VM.
    > Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at
    > PC=0x61044A01
    > Function=getservbyname+0xC1
    > Library=c:\sane\cygwin1.dll
    >
    > Current Java thread:
    > at org.sane.Sane.getNumberOfDevices(Native Method)
    > at com.phenix.framework.scan.ScanApplet.init(ScanApplet.java:227)
    > at sun.applet.AppletPanel.run(AppletPanel.java:353)
    > at java.lang.Thread.run(Thread.java:534)
    >
    > Does this mean that cygwin1.dll doesn't have the necessary
    > permissions to make the system call, or that there is a bug in
    > cygwin? As I said before, as an application, this works fine.


    More likely it means that you have incorrectly called getservbyname()
    from getNumberOfDevices(), for example by passing it (or another
    function that calls it) an invalid pointer.

    For some concrete suggestions, see this:
    http://www.eskimo.com/~scs/C-faq/q16.5.html

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Jun 11, 2004
    #10
  11. Dave Neary

    Dave Neary Guest

    Hi,

    In article <40c9baef$>, Gordon Beaton wrote:
    >> Does this mean that cygwin1.dll doesn't have the necessary
    >> permissions to make the system call, or that there is a bug in
    >> cygwin? As I said before, as an application, this works fine.

    >
    > More likely it means that you have incorrectly called getservbyname()
    > from getNumberOfDevices(), for example by passing it (or another
    > function that calls it) an invalid pointer.


    I didn't call it at all, but I will check the Sane source code for any
    obvious errors. Thanks for the help.

    > For some concrete suggestions, see this:
    > http://www.eskimo.com/~scs/C-faq/q16.5.html


    So this is the windows equivalent of a segfault?

    Cheers,
    Dave.
     
    Dave Neary, Jun 11, 2004
    #11
  12. On 11 Jun 2004 15:04:05 GMT, Dave Neary wrote:
    >> For some concrete suggestions, see this:
    >> http://www.eskimo.com/~scs/C-faq/q16.5.html

    >
    > So this is the windows equivalent of a segfault?


    I believe so.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Jun 11, 2004
    #12
  13. Dave Neary

    Dave Neary Guest

    Hi,

    On 11 Jun 2004 16:00:15 +0200, Gordon Beaton said:
    > More likely it means that you have incorrectly called getservbyname()
    > from getNumberOfDevices(), for example by passing it (or another
    > function that calls it) an invalid pointer.


    This isn't looking very likely... assuming of course that cygwin
    implements getservbyname correctly.

    The call is a simple

    serv = getservbyname ("sane", "tcp");

    the return is then checked, and it it's NULL, a default value is used.

    The only thing I can think of is that perhaps the cygwin parsing of
    /etc/services is incorrect and results in an error if the service isn't
    there. This is unlikely, though.

    I have updated cygwin to the latest version, and this no longer gives me
    an exception, it simply sticks in an infinite loop. It seems likely that
    the porblem is either with sane or cygwin.

    Thanks again,
    Dave.

    --
    David Neary,
    E-Mail: bolsh at gimp dot org
    Work e-mail: d dot neary at phenix dot fr
    CV: http://www.redbrick.dcu.ie/~bolsh/CV/CV.html
     
    Dave Neary, Jun 11, 2004
    #13
  14. Dave Neary

    Guest

    Dave Neary wrote:
    > Hi all,
    >
    > When I run the applet as an application (calling the constructor,

    init,
    > start, etc manually in the main method) all goes well, I get a scan.
    >
    > When I load the applet in a browser on Windows, however, it all goes
    > pear-shaped and the browser dies without a trace.
    >
    >
    > Thanks a lot,
    > Dave.


    Hi Dave,

    I know this thread is quite old now but I was wondering if you got this
    working in a browser on a Windows platform as I have a requirement to
    do pretty much the same thing.

    Thanks,

    Jimmy.
     
    , Mar 24, 2005
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Hooke

    Re: Handling both MS JVM and Sun JVM

    Kevin Hooke, Aug 26, 2003, in forum: Java
    Replies:
    2
    Views:
    879
  2. Alex Hunsley
    Replies:
    4
    Views:
    897
    Alex Hunsley
    Nov 14, 2003
  3. Lasse
    Replies:
    1
    Views:
    700
    Jon A. Cruz
    Jan 5, 2004
  4. Young-Jin Lee

    MS JVM and Sun JVM problem

    Young-Jin Lee, Jan 20, 2004, in forum: Java
    Replies:
    3
    Views:
    575
    Mickey Segal
    Jan 21, 2004
  5. Sumant  Sankaran
    Replies:
    1
    Views:
    731
Loading...

Share This Page