JVM and shared libraries

D

Dave Neary

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.
 
R

Roedy Green

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.
 
A

ALR

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
 
D

Dave Neary

Hi,

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.
 
D

Dave Neary

Hi Roedy,

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.
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 
A

alr

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...
 
D

Dave Neary

Hi,

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.
 
G

Gordon Beaton

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
 
D

Dave Neary

Hi,

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.
 
D

Dave Neary

Hi,

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.
 
G

Guest

Dave said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top