File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to call java method from c function?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to call java method from c function??" Watch "How to call java method from c function??" New topic
Author

How to call java method from c function??

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
How can we call the java method from c function??
Can any body have resources in this issue???
send to gali123@hotmail.com
Thanks advance
Srini
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
I am transferring this question to Java in General ( intermediate ) forum. Please use the JavaRanch forum only for issues related to the site and not for any technical discussions.
Thanks!


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Shubhrajit Chatterjee
Ranch Hand

Joined: Aug 23, 2001
Posts: 356
Hi,
I am also interested in knowing the answer to this question. I have thought of ways, but none are very good regarding performance.
1. The c program invokes the jvm and runs a java program which listens for connections over socket. Then this c program communicates with the java using sockets.
2. Sim to first. Only the communication is thru shared data files.


Shubhrajit
Jim Bertorelli
Ranch Hand

Joined: Nov 28, 2001
Posts: 136
Originally posted by Shubhrajit Chatterjee:

1. The c program invokes the jvm and runs a java program which listens for connections over socket. Then this c program communicates with the java using sockets.

That is what CORBA does, of course, with all the bells and whistles.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Gali and Shubhrajit,
I think the network option is still the best, even if not very good in terms of perf. If you go for that solution, consider using XML/RPC or SOAP.
Another solution would be to use JNI (Java Native Interface). Using the invocation API (see below), your C code can create a java virtual machine that communicates with your application.
The initialisation code should look like that:

Once created, you attach your thread to the JVM using the AttachCurrentThread method.
You can then call methods on java objects using the GetObjectClass, GetMethodID and CallXXXMethod methods on the JVM environment.
You can then detach your thread from the VM once finished.
See the tutorial on JNI on the Sun website: http://java.sun.com/docs/books/tutorial/native1.1/
The tutorial mentions that the JDK only supports attaching native threads on Win32. This was true at the time of writing but it is now possible on other systems (e.g. Solaris, Linux, etc...) as native threads are now available on those other OS.
Hope this helps,
Beno�t
[This message has been edited by Beno�t d'Oncieu (edited December 19, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call java method from c function??
 
Similar Threads
Calling DLL function
How to call java method from c function??
Calling C main() from Java
Calling a Java program in a C program
JOptionPane No X11 DISPLAY error