Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can we load multiple libraries into a single class with System.loadLib

Status
Not open for further replies.

abc73

Programmer
Apr 28, 2004
89
0
0
US
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 Ex
{
public native int A(String in);
public Ex()
{
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.

Can we load multiple libraries into a single class?
I want to load multiple libraries into a single class but doing that I get LinkError.

Any help is appreciated.

Thanks!
 
I never used JNI, but I have a question for you.

In class "Example" you have a method
Code:
public native int A(String in);
And in class "Ex" you have a method
Code:
public native int A(String in);
does that mean that the method is both in library "API2" and in library "API3" ?


 
not it's only in API3 the one in Example.java is public native int B(String in); I miss spelled it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top