System.loadLibrary in a package ?
is it possible to call the System.loadLibrarymethod from a class that is in a package?
when I tried to do the load from within the package, the librray was found, nut the functions in it weren't recognized.
but when I removed the class from the package, it worked fine.
my question: is it possible to return the class (with the System.loadLibrary method) back into the package?
tnx
tnx, but I'm not mixed upYes you are.
Where you call loadLibrary does not matter. It does the same thing regardless of where you call it.
>
>
any idea, how to solve this?
Your problem is because the method signatures do not match.
As suggested the most likely reason is because you did not regen and modify when the package changed. Next most likely reason is because you used javah incorrectly or you manually modified something in the signature that should not have.
Lastly if you are using class loaders, it is possible that that could cause a problem (I haven't confirmed this however, and I consider it unlikely.)
Similar Messages
-
System.LoadLibrary + dlopen -- callback causes unresolved symbol
Hi guys,
I am currently trying to use the API
System.loadLibrary(String name)in order to dynamically link shared libaries to SOLARIS JVM.
I am facing some unresolved symbol at run-time .
I load a shared library libhello1 (using system.LoadLibary)
and I call from this lib (via JNI interface) a method which
loads a second library libhello2(using dlopen) and invokes hello2().
hello2 will call back a method hello_bug which is implemented in libhello1.
There is the a mutual or cyclic dependence. This dependance is correctly handled if I link the libhello1 to a standard C implemented executable.
But if I load libHello1 via System.Load, the second lib is correctly loaded but the call back is not possible due to unresolved symbol.
It seems like the symbols are not kept in this case(or the dlopen creates a different thread?...)
The workaround to fix the issue is to link explicitely libHello1 to libHello2 when building libHello2.
I don't know if this is clear to everyone so
I have reproduced this on a very simple case.
Basicaly, I have implemented in standard C language 2 shared libraries:
libHelloModule1.so, libHelloModule2.so
one standard executable and one java interface to call the method
Below is the full code for reproduce:
hello1.h:
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <jni.h>
#include "hello_jni.h" [u]//automatically generated by javah -- ref Makefile[/u]
extern "C" void hello_bug();
hello1.cc :#include "hello1.h"
extern "C" {
JNIEXPORT void JNICALL Java_com_helloworld_Hello_ShowMessage
(JNIEnv *, jobject, jstring){
void *handle;
const char *error;
void (*init) (void);
printf(" load Hello2 \n");
handle = dlopen ("libHelloModule2.so", RTLD_LAZY);
printf (" lib Hello2 onload.. \n");
error = dlerror();
if (!handle) {
printf ("lib HelloModule2 not loaded correctly %s \n", error);
exit(1);
dlerror();
init =(void(*)()) dlsym(handle, "hello2");
error = dlerror();
if(error)
fprintf(stderr, "Could not find print_hello(): %s\n",
error);
exit(1);
(*init)();
dlclose(handle);
void hello_bug()
printf ("Hello bug correctly invoked : CQFD\n");
}// extern "C"
hello2.cc
#include "hello1.h"
typedef void ( *PF1) (char *, char *);
extern "C" {
void hello2(){
printf ("Hello2 : ping Hello1\n");
/*simple call work in c not via JNI*/
hello_bug();
Hello.java :
package com.helloworld;
import java.util.*;
import java.io.*;
public class Hello {
private native void ShowMessage(String msg);
public void initialized() {
System.out.println(" ShowMessage - called");
try {
ShowMessage("Generated with JNI");
} catch (Exception e ) {
e.printStackTrace(); }
public Hello(){
System.loadLibrary("HelloModule1");
System.out.println(" HelloModule1 loaded");
TestLocal.java :
import java.util.*;
import java.io.*;
import com.helloworld.Hello;
public class TestLocal{
public TestLocal(){
System.out.println("test local");
public static void main(String[] args) {
TestLocal test_local = new TestLocal();
Hello test = new Hello();
test.initialized();
}THE MOST IMPORTANT IS IN THE MAKEFILE:
Makefile :all: Hello.jar hello_jni.h libHelloModule1.so libHelloModule2.so TestLocal.class dummy
Hello.jar: com/helloworld/Hello.class
jar cvf $@ com/helloworld
com/helloworld/Hello.class: Hello.java
$(JAVAC) -d . Hello.java
hello_jni.h: Hello.jar
$(JAVAH) -jni -o $@ -classpath ./Hello.jar com.helloworld.Hello
libHelloModule1.so : hello_jni.h hello1.o
gcc -G -o $@ hello1.o -lstdc++
libHelloModule2.so : hello2.o
gcc -G -o $@ hello2.o -Wl -lstdc++ -L. -lHelloModule1 [u] # -->CASE 1 :THIS WORKS [/u]
gcc -G -o $@ hello2.o -Wl -lstdc++ [u] #-->CASE 2 :THIS DOES NOT WORK[/u]
dummy : dummy_main.o
gcc -o $@ dummy_main.o -L. -lHelloModule1 -L/usr/local/lib -lstdc++
hello2.o : hello2.cc
gcc -I. -O -c hello2.cc
hello1.o : hello1.cc
gcc -I. -O -c hello1.cc
TestLocal.class : TestLocal.java
$(JAVAC) -classpath . -d . TestLocal.java
dummy_main.o : dummy_main.cc
gcc -I. -O -c dummy_main.cc
clean:
rm -rf com *.o *.so *.class *.jar hello_jni.h dummyCASE 1 : libHelloModule1.so is explicitely linked to libHelloModule2
myhost % dummy
load Hello2
lib Hello2 onload..
Hello2 : ping Hello1
Hello bug correctly invoked : CQFD
myhost % java -cp . TestLocal
test local
HelloModule1 loaded
ShowMessage - called
load Hello2
lib Hello2 onload..
Hello2 : ping Hello1
Hello bug correctly invoked : CQFD
CASE 2 : libHelloModule1.so is not explicitely linked to libHelloModule2
myhost % dummy
load Hello2
lib Hello2 onload..
Hello2 : ping Hello1
Hello bug correctly invoked : CQFD
myhost % java -cp . TestLocal
test local
HelloModule1 loaded
ShowMessage - called
load Hello2
lib Hello2 onload..
lib HelloModule2 not loaded correctly ld.so.1: java: fatal: relocation error: file ./libHelloModule2.so: symbol hello_bug: referenced symbol not found
My concern is to have this working in CASE1 with the JNI interface the same way it does in standard C built runtime.
So does any have encountered this?
Is there something I missed somewhere?
Thanks lot for your help
YoussHi,
I have implemented JNative which seems to be close to your problem.
It works under Windows and Linux, and loads libraries via dlopen and dlsym.
You can have a look at it's implementation at http://jnative.cvs.sourceforge.net/jnative/JNativeCpp/
Don't forget to load your libraries before trying to call them with System.load("/path/to/your/lib.so"); if they are not referenced by LD_LIBRARY_PATH.
This post may be false since I know nothing about Solaris. Perhaps JNative may be ported under Solaris ?
--Marc (http://jnative.sf.net) -
System.loadLibrary in SunOne Debug
How do I add a new JNI library file to the debug library path so I can use it for debugging?
Your DLL files must be packages in a Jar file not on the client's file system. The JAR must also be specified in your JNLP file with the nativelib tag in the resources section.
When you call System.loadLibrary() do not include the .dll extension (I learned this one the hard way today). -
Hello,
Someone please help me. What I am trying to do is load two .DLL files in my program. Program works fine when I
do the following way i.e. I have two .java files and in each I am loading one .DLL file. But I don't want to have
two .java files I want to load both the .DLL files in one program.
**************** Example.java **********
import java.io.*;
import java.util.*;
public class Example
public native int A(String in);
static
System.loadLibrary( "API2" );
public static void main( String args[])
Ex ex = new Ex();
int r;
r = ex.A("TEST");
public Example()
*****************Ex.java*****************
public class exsysml
public native int A(String in);
public exsysml()
System.loadLibrary("API3");
The above way works. But I need only one .java file to load both the .DLL files. i.e.
import java.io.*;
import java.util.*;
public class Example
public native int A(String in);
static
System.loadLibrary( "API2" );
System.loadLibrary( "API3" );
public static void main( String args[])
Example ex = new Example();
int r;
r = ex.A("TEST");
public Example()
but when I do this way it doesn't work and I get a UnSatisfiedLinkage Error at ex.A("TEST"). While doing the top way it works.
How can I fix this to just have one .java file and load both the library files as done in the bottom program but doing this program doesn't work. Any help is appreciated.
Thanks!what I figured out so far is that we can only load one library file in a single class and define all the native methods present in that library in the class where we are loading it. Means we can't load multiple library files in a single class. It's just my thought else if someone provides a better solution. I may be wrong so that's why I need your help.
Thanks -
System.loadLibrary works in 1.3.1 but not in 1.2.2
I Have a basic hello world application on Sun Solaris 7 that calls C++ from Java using JNI.
The code works well on 1.3.1, but when I recompile it under 1.2.2 and run I get the following exception when I call System.loadLibrary to load my shared library:
java.lang.UnsatisfiedLinkError: no MyLib in java.library.path
My LD_LIBRARY_PATH is set correctly since it worked under 1.3.1.
Just in case, I used the following code to get and set the java.library.path to no avail.
// Check System properties
String strLibPath = System.getProperty("java.library.path");
System.out.println("The Lib Path before set == " + strLibPath);
StringBuffer strLibPathBuffer = new StringBuffer("/u/kbonacc/mypath:");
strLibPathBuffer.append(strLibPath);
System.setProperty("java.library.path", strLibPathBuffer.toString());
strLibPath = System.getProperty("java.library.path");
System.out.println("The Lib Path after set == " + strLibPath);
Are there any differences between 1.3.1 and 1.2.2 in this respect?
Thanks,
-- KenIn the bug parade I've heard excuses from Sun programmers that this is a read-only property and isn't supposed to be changed. It probably took them longer to write the reply to the bug than it would have to fix the code.
I looked at the source code for the ClassLoader and for the source release of the JDK 1.3.1 and here's the code I found in the ClassLoader.loadLibrary() method:
if (sys_paths == null) {
usr_paths = initializePath("java.library.path");
sys_paths = initializePath("sun.boot.library.path");
}It seems it parses and caches the system and user library paths on startup and then never bothers to check them to see if they've changed ever again. I think it would be pretty simple to rewrite that code block by moving one line of code down two lines as this:
if (sys_paths == null) {
sys_paths = initializePath("sun.boot.library.path");
usr_paths = initializePath("java.library.path");I mean, it's not as if loadLibrary is really performance intensive or even critical enough to bother caching at all!
This one code change could fix a lot of headaches.
The particular headache I'm working on is that there doesn't seem to be any support in the Servlet 2.2 or 2.3 specification for JNI files. I'd really love to be able to use a directory like WEB-INF\jni to store libraries that need to be distributed with my web application. I tried to dynamically change java.library.path to include WEB-INF\jni, but alas I ran into the same problem you did, it doesn't work.
Is is possible for this to be fixed, ever? I think it would take longer to say no and make up a reason why not then it would to actually make the fix... seems a good enough arguement to do it to me.
And alternately, can we come up with a standard place to put JNI stuff for web applications in the next Servlet standards?
Thanks in advance!
-J.C.
[email protected] -
JNI System.loadLibrary troubles
Hello again!
I am so close to finishing this program I can taste it! But�
OK, I am doing a bit of JNI. All appears to be well except my program can�t seem to use
System.loadLibrary("myCPPdll");
to find the dll file I need to run the C++ code.
I�ve tired replacement with
Runtime.getRuntime().loadLibrary("myCPPdll ");
just for grins with the same result.
I also tried
System.loadLibrary("C:/fullPath/myCPPdll");
with no luck.
The error message I get, regardless if I run from the command line or via Eclipse is
java.lang.UnsatisfiedLinkError: no myCPPdll in java.library.path.
Possibly related: when I use the tutorial form
Static
System.loadLibrary("myCPPdll");
my compiler tells me it can�t find the main. Just how critical is it to have it in this static format? It compiles great without the System call embedded in the static{} block!
Thanks for your time!I added the .dll and get the same error. It was my
understanding that System.loadLibrary(fileName)
automatically added the file to the library path for
the individual program in question. If this is not
the case, could you please elaborate a bit on adding
it to the path?
No, in effect it searches the path to find the dll library. You need to (re-)read the tutorial -
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/step5.html -
How to view list of all system exceptions from standard package?
Hello,
How to view list of all system exceptions from standard package?
Regards
KrishnaJust for fun:
SQL> conn sys/****** as sysdba
Verbonden.
SQL> select cast(trim(substr(text,instr(text,'(')+1,instr(text,',')-instr(text,'(')-1)) as varchar2(30)) exception_name
2 , to_number(replace(substr(text,instr(text,',')+1,instr(text,')')-instr(text,',')-1),'''')) error_number
3 from user_source
4 where text like '%pragma EXCEPTION_INIT%'
5 and type = 'PACKAGE'
6 and name = 'STANDARD'
7 order by exception_name
8 /
EXCEPTION_NAME ERROR_NUMBER
ACCESS_INTO_NULL -6530
CASE_NOT_FOUND -6592
COLLECTION_IS_NULL -6531
CURSOR_ALREADY_OPEN -6511
DUP_VAL_ON_INDEX -1
INVALID_CURSOR -1001
INVALID_NUMBER -1722
INVALID_OBJECT_NAME -44002
INVALID_QUALIFIED_SQL_NAME -44004
INVALID_SCHEMA_NAME -44001
INVALID_SQL_NAME -44003
LOGIN_DENIED -1017
NO_DATA_FOUND 100
NO_DATA_NEEDED -6548
NOT_LOGGED_ON -1012
PROGRAM_ERROR -6501
ROWTYPE_MISMATCH -6504
SELF_IS_NULL -30625
STORAGE_ERROR -6500
SUBSCRIPT_BEYOND_COUNT -6533
SUBSCRIPT_OUTSIDE_LIMIT -6532
TIMEOUT_ON_RESOURCE -51
TOO_MANY_ROWS -1422
USERENV_COMMITSCN_ERROR -1725
VALUE_ERROR -6502
ZERO_DIVIDE -1476
26 rijen zijn geselecteerd.Regards,
Rob. -
Jni library loaded by System.load fails on later call to System.loadLibrary
I'm attempting to use jnotify to listen for directory modifications. This requires using jni to dynamically link to a c library. I have gotten everything to work successfully if I put the library on the java.library.path. However, I would prefer to let my application specify the full path to the jnotify library. My understanding is that I should be able to do a System.load("/foo/libjnotify.so") in a static block and then subsequent calls to System.loadLibrary("jnotify") should do nothing as the library is already loaded. However I am getting a 'Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnotify in java.library.path'. Am I misunderstanding the correct usage of these System calls?
Joe wrote:
That makes sense.
The System.loadLibrary portion is in a 3rd party library which I am legally not allowed to change.
Are there any other possible ways to accomplish the loading without the library being on the java.library.path?
You have two problems - not one.
The library itself is calling loadLibrary(). The standard idiom is that one does that in a static block. If a static block throws an exception, any exception, then the class will not load.
Presumably the library is not checking for a duplicate library load. So your problem is that that loadLibrary() call must not throw an exception.
Thus you cannot preload the library.
Far as I can see you have the following options.
- Put it on the path.
- Create a jave exec handler (via Runtime.exec or jni), put the library on that path before you start another VM which does the real work.
- Modify the java API loadLibrary() call so it catches the dup exception, that of course requires a boot option. -
Cannot load sharedfile.so by System.LoadLibrary() in a remote machine
Hi, I am facing a weired problem. I have written a very simple java native interface program that works fine in my computer. But when I
ssh to another machine and run the same code there..
class TestJni
static
try
System.loadLibrary( "test" );
catch( UnsatisfiedLinkError e )
* System.out.println("Could not load native code for user authentication." ); *
System.exit(1);
public static void main( String [] args )
public static native int sum( int x, int y );
The output is: Could not load native code for user authentication.. which means the catch block has executed and the program is not being able to
load the shared library. To run the code I am doing something like this:
LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH java TestJni
this works fine in my pc... but is there any limitation in running the code remotely.. this does not make any sense though...It's a bug, fixed in TT 7.0.4.
-
Hello,
I have a problem about jDriver
the configuration is:
solaris 8
WLS 6.1 sp2
Oracle9i 9.0.1
jDriver oci 901_8
(Weblogic server and Oracle db in same machine)
I follow the "Installing WebLogic jDriver for Oracle" setting from BEA online
documantation.
but I got some error and exception as follow:
Could not create pool connection. The DBMS driver exception was:
java.sql.SQLException: System.loadLibrary(weblogicoci37) threw java.lang.UnsatisfiedLinkError:
/export/home/bea/wlserver6.1/lib/solaris/oci901_8/libweblogicoci37.so: ld.so.1:
/export/home/bea/jdk131/jre/bin/../bin/sparc/native_threads/java: ?P?R??: /usr/local/oracle/OraHome1/lib/libclntsh.so.9.0:
???~?? ELF ??§O?G ELFCLASS64
at weblogic.jdbc.oci.Driver.loadLibraryIfNeeded(Driver.java:226)
at weblogic.jdbc.oci.Driver.connect(Driver.java:76)
somebody can give me a hang,thanks!!!
-WinsonYou need to have /export/home/bea/wlserver6.1/lib/solaris/oci901_8 in your LD_LIBRARY_PATH env variable so that the library
can be found and loaded dynamically. Check the startWebLogic.sh script for an example and make sure that it is getting set
appropriately when you start the server.
Bill
Winson Lee wrote:
Hello,
I have a problem about jDriver
the configuration is:
solaris 8
WLS 6.1 sp2
Oracle9i 9.0.1
jDriver oci 901_8
(Weblogic server and Oracle db in same machine)
I follow the "Installing WebLogic jDriver for Oracle" setting from BEA online
documantation.
but I got some error and exception as follow:
Could not create pool connection. The DBMS driver exception was:
java.sql.SQLException: System.loadLibrary(weblogicoci37) threw java.lang.UnsatisfiedLinkError:
/export/home/bea/wlserver6.1/lib/solaris/oci901_8/libweblogicoci37.so: ld.so.1:
/export/home/bea/jdk131/jre/bin/../bin/sparc/native_threads/java: ?P?R??: /usr/local/oracle/OraHome1/lib/libclntsh.so.9.0:
???~?? ELF ??§O?G ELFCLASS64
at weblogic.jdbc.oci.Driver.loadLibraryIfNeeded(Driver.java:226)
at weblogic.jdbc.oci.Driver.connect(Driver.java:76)
somebody can give me a hang,thanks!!!
-Winson -
"specified handle or index is not valid" on System.loadLibrary
Hi,
I have a WAS 6.40 installation on HPUX 11i. I am using a native method in one of the login modules I have made, but am getting the following error (stack trace shown below):
[Jan 11, 2005 11:33:27 AM - 10 - Err] java.lang.UnsatisfiedLinkError: /usr/lib/libJDecrypt.sl: specified handle or index is not valid.
[Jan 11, 2005 11:33:27 AM - 10 - Err] 0: java.lang.ClassLoader$NativeLibrary.load(Native Method)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 1: java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1611)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 2: java.lang.ClassLoader.loadLibrary(ClassLoader.java:1511)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 3: java.lang.Runtime.loadLibrary0(Runtime.java:795)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 4: java.lang.System.loadLibrary(System.java:834)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 5: com.netegrity.siteminder.sap.webas.util.JavaDecrypt.<clinit>(JavaDecrypt.java:56)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 6: com.netegrity.siteminder.sap.webas.jaas.SiteMinderLoginModule.<clinit>(SiteMinderLoginModule.java:146)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 7: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 8: sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 9: sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 10: java.lang.reflect.Constructor.newInstance(Constructor.java:274)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 11: java.lang.Class.newInstance0(Class.java:308)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 12: java.lang.Class.newInstance(Class.java:261)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 13: com.sap.engine.services.security.login.LoginContextFactory.initializeLoginContext(LoginContextFactory.java:160)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 14: com.sap.engine.services.security.login.FastLoginContext.login(FastLoginContext.java:127)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 15: com.sap.engine.services.servlets_jsp.server.runtime.context.SessionServletContext.doLogin(SessionServletContext.java:619)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 16: com.sap.engine.services.servlets_jsp.server.runtime.context.SessionServletContext.checkUser(SessionServletContext.java:294)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 17: com.sap.engine.services.servlets_jsp.server.runtime.context.ApplicationContext.checkMap(ApplicationContext.java:403)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 18: com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.checkRequest(HttpHandlerImpl.java:67)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 19: com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:780)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 20: com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:239)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 21: com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 22: com.sap.engine.services.httpserver.server.Processor.request(Processor.java:147)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 23: com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 24: com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 25: com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 26: java.security.AccessController.doPrivileged(Native Method)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 27: com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)
[Jan 11, 2005 11:33:27 AM - 10 - Err] 28: com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:162)
Strangely when I try to load the .sl library from a test application outside WAS it loads perfectly. Have tested a similar DLL on a WAS setup on Windows. It works fine there.
regards,
VishalHi Markus,
Thanks for pointing out the problem. I was suspecting the same too.
Unfortunately we are also using some third party libraries, which happen to be 32-bit. Would need a workaround somehow.
Could you mention the location from where u got the info regarding PAM on HPUX? As in where is it documented etc.?
regards,
Vishal -
Error with System.loadLibrary("msvcr80");
Hi,
I am trying to test a library somebody wrote and that library is using msvcr80.dll
So in my little java test program goes like this:
try {
System.loadLibrary("advapi32");
System.loadLibrary("msvcr80");
// code removed for simplicity
} catch (UnsatisfiedLinkError e) {
System.err.println("Library failed to load.\n" + e);
}But I always get an exception when trying to load msvcr80:
Runtime Error!
Program: C:\Program Files\Java\jre6\bin\javaw.exe
R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
What's the problem? The DLL can be found no problem (it's in the path pointed by java.library.path) but cannot be loaded. Is there another DLL that needs to be loaded beforehand besides advapi32?
Thanks.Symbul wrote:
Hi,
Yes I know winsxs is not in the PATH, but I put it there just for test purposes. By the way I get the same C runtime javaw.exe error when I try to load ANY library that has a dependency on MSVCR80 (even microsoft DLLs, 3rd party JNI, etc.) and I'm not the only one in the office that has the problem either. Using Process Explorer I can see all the DLLs (every location) that are load by each applications and there is only one that's in memory and it's the correct one, so I'm quite puzzled as what could be wrong here.
1. This is a JNI forum which this obviously is about.
2. Please tell us what the problem is rather than asking why your solution doesn't work.
3. Post the actual exception.
4. And verify that you are NOT using windows 7, nor any 64 bit VM.
Normally the MSVCR80 dll would be loaded dynamically by the OS when the reference of some other library requested it. In this case the most likely reason is because the dependent library (or some other) is not in the shared library path. -
Catching System.loadLibrary exceptions
I looked at the JNI book examples, and none does that. So i conclude that it is better to let that exception propagate up the stack. It makes sense because otherwise class behavior would be undefined. If you have evidence to the contrary, please speak up.
Thanks.
chap2/HelloWorld/HelloWorld.java- static {
chap2/HelloWorld/HelloWorld.java: System.loadLibrary("HelloWorld");
chap2/HelloWorld/HelloWorld.java- }
chap2/HelloWorld/HelloWorld.java-}
chap3/IntArray/IntArray.java- static {
chap3/IntArray/IntArray.java: System.loadLibrary("IntArray");
chap3/IntArray/IntArray.java- }
chap3/IntArray/IntArray.java-}
chap3/IntArray2/IntArray.java- static {
chap3/IntArray2/IntArray.java: System.loadLibrary("IntArray");
chap3/IntArray2/IntArray.java- }
chap3/IntArray2/IntArray.java-}
chap3/ObjectArrayTest/ObjectArrayTest.java- static {
chap3/ObjectArrayTest/ObjectArrayTest.java: System.loadLibrary("ObjectAr
ayTest");
chap3/ObjectArrayTest/ObjectArrayTest.java- }
chap3/ObjectArrayTest/ObjectArrayTest.java-}
chap3/Prompt/Prompt.java- static {
chap3/Prompt/Prompt.java: System.loadLibrary("Prompt");
chap3/Prompt/Prompt.java- }
chap3/Prompt/Prompt.java-}
chap3/Prompt2/Prompt.java- static {
chap3/Prompt2/Prompt.java: System.loadLibrary("Prompt");
chap3/Prompt2/Prompt.java- }
chap3/Prompt2/Prompt.java-}
chap4/InstanceFieldAccess/InstanceFieldAccess.java- static {
chap4/InstanceFieldAccess/InstanceFieldAccess.java: System.loadLibrary("
nstanceFieldAccess");
chap4/InstanceFieldAccess/InstanceFieldAccess.java- }
chap4/InstanceFieldAccess/InstanceFieldAccess.java-}
chap4/InstanceFieldAccess2/InstanceFieldAccess.java- static {
chap4/InstanceFieldAccess2/InstanceFieldAccess.java: System.loadLibrary(
InstanceFieldAccess");
chap4/InstanceFieldAccess2/InstanceFieldAccess.java- }
chap4/InstanceFieldAccess2/InstanceFieldAccess.java-}
chap4/InstanceMethodCall/InstanceMethodCall.java- static {
chap4/InstanceMethodCall/InstanceMethodCall.java: System.loadLibrary("In
tanceMethodCall");
chap4/InstanceMethodCall/InstanceMethodCall.java- }
chap4/InstanceMethodCall/InstanceMethodCall.java-}
chap4/InstanceMethodCall2/InstanceMethodCall.java- static {
chap4/InstanceMethodCall2/InstanceMethodCall.java: System.loadLibrary("I
stanceMethodCall");
chap4/InstanceMethodCall2/InstanceMethodCall.java- initIDs();
chap4/InstanceMethodCall2/InstanceMethodCall.java- }
chap4/InstanceMethodCall2/InstanceMethodCall.java-}
chap4/MyNewString/MyNewString.java- static {
chap4/MyNewString/MyNewString.java: System.loadLibrary("MyNewString");
chap4/MyNewString/MyNewString.java- }
chap4/MyNewString/MyNewString.java-}
chap4/MyNewString2/MyNewString.java- static {
chap4/MyNewString2/MyNewString.java: System.loadLibrary("MyNewString");
chap4/MyNewString2/MyNewString.java- }
chap4/MyNewString2/MyNewString.java-}
chap4/StaticFieldAccess/StaticFieldAccess.java- static {
chap4/StaticFieldAccess/StaticFieldAccess.java: System.loadLibrary("Stat
cFieldAccess");
chap4/StaticFieldAccess/StaticFieldAccess.java- }
chap4/StaticFieldAccess/StaticFieldAccess.java-}
chap4/StaticMethodCall/StaticMethodCall.java- static {
chap4/StaticMethodCall/StaticMethodCall.java: System.loadLibrary("Static
ethodCall");
chap4/StaticMethodCall/StaticMethodCall.java- }
chap4/StaticMethodCall/StaticMethodCall.java-}
chap5/MyNewString/MyNewString.java- static {
chap5/MyNewString/MyNewString.java: System.loadLibrary("MyNewString");
chap5/MyNewString/MyNewString.java- }
chap5/MyNewString/MyNewString.java-}
chap6/CatchThrow/CatchThrow.java- static {
chap6/CatchThrow/CatchThrow.java: System.loadLibrary("CatchThrow");
chap6/CatchThrow/CatchThrow.java- }
chap6/CatchThrow/CatchThrow.java-}
chap6/InstanceMethodCall/InstanceMethodCall.java- static {
chap6/InstanceMethodCall/InstanceMethodCall.java: System.loadLibrary("In
tanceMethodCall");
chap6/InstanceMethodCall/InstanceMethodCall.java- }
chap6/InstanceMethodCall/InstanceMethodCall.java-}
chap6/ThrowByName/ThrowByName.java- static {
chap6/ThrowByName/ThrowByName.java: System.loadLibrary("ThrowByName");
chap6/ThrowByName/ThrowByName.java- }
chap6/ThrowByName/ThrowByName.java-}
chap8/NativeString/NativeString.java- static {
chap8/NativeString/NativeString.java: System.loadLibrary("NativeString")
chap8/NativeString/NativeString.java- }
chap8/NativeString/NativeString.java-}
chap9/OneToOne/OneToOne.java- static {
chap9/OneToOne/OneToOne.java: System.loadLibrary("OneToOne");
chap9/OneToOne/OneToOne.java- }
chap9/OneToOne/OneToOne.java-}
chap9/OneToOne/OneToOne.java-
chap9/SharedStubs/CPointer.java- static {
chap9/SharedStubs/CPointer.java: System.loadLibrary("disp");
chap9/SharedStubs/CPointer.java- SIZE = initIDs();
chap9/SharedStubs/CPointer.java- }
chap9/SharedStubs/CPointer.java-There are 2 choices, i guess:
1) Catch and don't re-throw, thus allowing pure java methods to be called,
even though native method calls will throw, and state might be undefined.
2) Catch and don't re-throw: thus making all method calls on such a class
to throw, since object instantiations will fail. But at least in this
case, an object w/ undefined behavior won't be in use.
And i guess one could choose one or the other based on circumstances. In
my case, the class will pretty much be unworkable w/o native methods, so
what would be the best choice?
Looking at NetBeans source, i'm seeing 2 examples of 1, and 1 example of
2. Both examples of 1 utilize fail-backs if library isn't found, such as
not calling the native method involved. The example of 2, catches
Exception but lets Throwables go thru, which means it doesn't catch
UnsatisfiedLinkError, and NbDdeBrowserImpl is unusable it library isn't
found. My situation is similar to this. I concluded for myself, that we
should catch all 3 exceptions from System.loadLibrary, show error dialog
w/ each exception's message, and re-throw each exception, because
otherwise, 90% of methods in the class are going to throw, and there is no
way to get any decent functionality out of it in such a situation. Would
you agree w/ my conclusion?
1.1)
/tasklist/core/src/org/netbeans/modules/tasklist/core/Background.java
private static void loadLibrary() {
if (loadfailed) return;
if (false == loaded) {
try {
// XXX be aware of #32080, that changes location of native
libraries
System.loadLibrary("tasklist_bgthreads"); // NOI18N
loaded = true;
} catch (Throwable t) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, t);
loadfailed = true;
1.2)
tasklist/timerwin/src/org/netbeans/modules/tasklist/timerwin/AlwaysOnTop.java:
try {
setAlwaysOnTopMethod = Window.class.getDeclaredMethod(
"setAlwaysOnTop", // NOI18N
new Class[] {Boolean.TYPE});
} catch (Throwable t) {
// ignore
if (setAlwaysOnTopMethod == null) {
try {
System.loadLibrary("alwaysontop"); // NOI18N
libLoaded = true;
} catch (Throwable t) {
libLoaded = false;
2) extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
try {
if (org.openide.util.Utilities.isWindows()) {
// should be 32 or 64 bit, but it may not be present on
some jdks
String sunDataModel =
System.getProperty("sun.arch.data.model"); //NOI8N
if (sunDataModel != null) {
if ("64".equals(sunDataModel)) { //NOI18N
System.loadLibrary(EXTBROWSER_DLL_64BIT);
} else {
System.loadLibrary(EXTBROWSER_DLL);
} else {
String javaVMName =
System.getProperty("java.vm.name"); //NOI8N
if ((javaVMName != null) && (javaVMName.indexOf("64")
-1)) { //NOI18NSystem.loadLibrary(EXTBROWSER_DLL_64BIT);
} else {
System.loadLibrary(EXTBROWSER_DLL);
} catch (Exception e) {
DialogDisplayer.getDefault ().notify (
new
NotifyDescriptor.Message(NbBundle.getMessage(NbDdeBrowserImpl.class,
"ERR_cant_locate_dll"),
NotifyDescriptor.INFORMATION_MESSAGE)
} -
Where to perform System.loadLibraryI()
I have a Java web app that uses JSPs and servlets. The JSPs use an object that needs a DLL loaded through System.loadLibrary().
When I put the code into the object's static initializer, I get an "Another loader has already loaded this library" exception.
First of all, the javadocs say that this function doesn't throw an exception if the library is already loaded.
Second of all, where is a good place to load this DLL?
Brett Slocum
[email protected]P.S. I've tried putting the loadLibrary() call in the init() of a servlet in the system, but then I get a "library not loaded" message in the JSP.
-
System.loadLibrary Hangs
I have a .dll used for address verification and I wrote a JNI wrapper .dll in C++ so I could use it with my application. I wrote a class with both a main method and constructor method and the class works fine at the command prompt. When I try to use the class with my application it hangs at the System.loadLibrary command. I'm using JRun 4 on a Win 2k server. I set the java.library.path to the location of the .dll and made sure all necessary files were in that folder. Any helpful suggestions would be appreciated. Thanks.
A hang at that point in time means it has nothing to do with java.
The dll probably has a dllmain method (or whatever it is called.) That method is being called and is never returning. You need to figure out why.
Maybe you are looking for
-
Edit - solved - needed to remove present mdbdata folder contents before starting a restore. Bit of a long post, sorry - trying to tell the whole story. I run SBS2003 in a virtual machine. I stop the VM and copy the virtual disk file to another drive
-
Declare Types using a custom table
Hi, I am creating a new structure in my program in ABAP Editor. The fields of this table will be all the fields in a custom table plus an additional field which is not a part of this table. The table has some 150 fields so I need to include it in my
-
How to pass in a parameter into a report viewer on a jsp - and hidden
Hi, I've built a php application and am using the java environment to enable the crystal report/viewer. The developer was looking how to pass in a parameter into a report viewer on a jsp. Ultimately the end product we need is to get an HTML report v
-
I am trying to move up from flex 1.5 to 3 Is new release clairgorm framework planned for flex 3 (last one I saw was 2.1) I really like that framework , now it is from Adobe labs Sould I use 2.1 version for flex 3 etc... I will appreciate any comments
-
G4 rejects or fails to initialize any DVD I offer it
Any help on this would be super-appreciated... I am running OS9.2.2 on my G4 (silver door) and it has always burned data CDs easy peasy. I tried to burn a data DVD yesterday and I'm really running into problems: When I put a blank DVD and close the t