• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI Dll Problem

 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi Guys,

ok here is the problem

i am trying to write the above JNI code to call the main.dll
i am able to compile it fine, but when i try to create a .h file it gives me errors

command i am using us javah -jni CallingC

error: cannot access CallingC
file CallingC.class not found
javadoc: error - Class CallingC not found.
Error: No classes were specified on the command line. Try -help.

Having said that,

This is my agenda

1. Call main.dll ( This used to be a .exe, but i changed the make script and changed it to a dll)
2. Main.dll internally calls another dll ( This calling used to work fine when it was main.exe,so i assumed it will work if i call it from a JNI program)

Any suggestions




 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try making the class public, and make sure it's in the classpath when running javah (maybe by using "-classpath .").
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:Try making the class public, and make sure it's in the classpath when running javah (maybe by using "-classpath .").


ok i have done the public part.
The class path and path part really confuses me.

should i be typing in something like javah -classpath jni ClassName ??
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like

javah -jni -o main.h -classpath . CallingC

assuming that CallingC is in no package -which it really should be- and that the class file is in the current directory.
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sankey jain wrote:
Lester Burnham wrote:Try making the class public, and make sure it's in the classpath when running javah (maybe by using "-classpath .").


ok i have done the public part.
The class path and path part really confuses me.

should i be typing in something like javah -classpath jni ClassName ??


Further to above quote

made it public, used class path got the below error
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:Something like

javah -jni -o main.h -classpath . CallingC

assuming that CallingC is in no package -which it really should be- and that the class file is in the current directory.


Thats worked

 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:Something like

javah -jni -o main.h -classpath . CallingC

assuming that CallingC is in no package -which it really should be- and that the class file is in the current directory.


Ok, Now that Header is created, What do i do.
I already have the dll, ( it was there before i compiled the header file)

i tried the below
After this, i tried this

Ignore the filename change, i have written a new one

Java Test1.java

C:\callDll>java c:\callDll\Test1
Exception in thread "main" java.lang.NoClassDefFoundError: c:\callDll\Test1
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:Something like

javah -jni -o main.h -classpath . CallingC

assuming that CallingC is in no package -which it really should be- and that the class file is in the current directory.


My problem is slightly different

There are 2 dll's
i need to call dll 1 via java, which in turn will call dll 2 internally.

dll1 used to be a .exe, but i changed the make file, and configured it be saved as .dll
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "java" executable -just like "javah"- does not take a file name as parameter, it takes a class name. You also need to make sure that the DLL library is in your PATH.
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:The "java" executable -just like "javah"- does not take a file name as parameter, it takes a class name. You also need to make sure that the DLL library is in your PATH.




I am working with Eclipse C/C++ IDE

I am getting the above errors in the code
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!