aspose file tools*
The moose likes Servlets and the fly likes Problem in running JNI with in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in running JNI with in servlet" Watch "Problem in running JNI with in servlet" New topic
Author

Problem in running JNI with in servlet

Swaroop Reddy
Ranch Hand

Joined: Feb 25, 2009
Posts: 34
Hi All,
I am doing POC on JNI calling Native methods from servlet.The code I am posting here had worked fine for stand alone application,but when i work it out in servlet its giving an


Please find my code below
1.
I am making this as a jar file to call it from servlet for ease use

2.

and finally in my servlet class I am calling the jar file created above at using prog1.java
3.my servlet file(giving only the method used in servlet)


but after running the servlet I am getting an error

java.lang.UnsatisfiedLinkError: sum
at prog.prog1.sum(Native Method)
at prog.prog1.Sum(prog1.java:25)
at prog1.main(prog1.java:27)


I refered the forums they are saying like put the dll in java.library path
my library path is
C:\j2sdk1.4.2_04\bin;.;C:\WINDOWS\system32;C:\WINDOWS;D:\Oracle\product\10.1.0\
Client_2\bin;D:\Oracle\product\10.1.0\Client_2\jre\1.4.2\bin\client;D:\Oracle\
product\10.1.0\Client_2\jre\1.4.2\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\
System32\Wbem;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\
Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;
C:\j2sdk1.4.2_04\bin;C:\j2sdk1.4.2_04\bin\include;C:\j2sdk1.4.2_04\bin\include\win32;
C:\J2SDK1.4.2_04\BIN


where should i include my prog1.dll file

Please help me to resolve the problem ,no specific data though googled,
thank you in prior


Mr.Reddy
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

The DLL is not getting loaded. The system property to refer is java.library.path. That usually solves the problem.

Debug just before you load the library and use the Display view in eclipse to obtain the java.library.path value. Check if this contains the directory where your DLL resides. Try a System.loadLibrary() in the Display view after this is done.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Swaroop Reddy
Ranch Hand

Joined: Feb 25, 2009
Posts: 34
Deepak Bala wrote:The DLL is not getting loaded. The system property to refer is java.library.path. That usually solves the problem.
Debug just before you load the library and use the Display view in eclipse to obtain the java.library.path value. Check if this contains the directory where your DLL resides. Try a System.loadLibrary() in the Display view after this is done.




Hi,I checked the same as you specified still it is giving same error.I got the library path and added my dll to that path ,but still its giving same error


Please any one can solve my problem
krish rajini
Greenhorn

Joined: Jul 02, 2008
Posts: 25
Add your .dll file in System32 folder

or anyother folder if you want.But if you use some other folder

try inserting the complete absolute path of the file.

In System.load("absolute path");

first do the console JNI application .

Then later add the servlet packages and doGet functions.

do the same procedure what you have done with console application.

except copy the .class servlet file in WEB-INF/classes folder.

check your web.xml file also.

if this all done correctly.It should work .

i tried with apache tomcat 6.0.20
 
 
subject: Problem in running JNI with in servlet