How to call Java from C++?

T

tony_lincoln

Dear Friends,

I know that if you call C++ from java, you have to use JNI. But how to
call Java from C++?

Thanks a lot.
Tony
 
G

Gordon Beaton

I know that if you call C++ from java, you have to use JNI. But how
to call Java from C++?

Much of what you do in native methods involves making calls from C to
Java methods, or accessing fields in Java objects. In other words
there is no real distinction, you use JNI for calls in both
directions.

If you also want to launch a JVM from C, there are a small number of
functions described in the JNI spec under "invocation" for just that
purpose.

/gordon
 
J

jan V

Are there any other better methods except JNI?

Can the C++ program be changed? If so, how about letting the two talk over
some TCP connection? Or use CORBA if sockets are too low level for you..
 
T

tony_lincoln

Unfortunately C++ program is huge and can not be changed. Is there any
better solutions?Thank a lot.
 
J

jan V

Unfortunately C++ program is huge and can not be changed.

Well, if it can NOT be changed, and it doesn't ALREADY have a C -> Java
communications solution in place, then clearly you're going to need magic to
make it communicate with Java, or am I missing something here?
 
J

Joan

jan V said:
Well, if it can NOT be changed, and it doesn't ALREADY have a
C -> Java
communications solution in place, then clearly you're going to
need magic to
make it communicate with Java, or am I missing something here?
I think the OP means that he should do nothing and tomorrow
morning it works.
 
J

Joan

jan V said:
Well, if it can NOT be changed, and it doesn't ALREADY have a
C -> Java
communications solution in place, then clearly you're going to
need magic to
make it communicate with Java, or am I missing something here?
Sorry, I forgot, you can use pipes.
 
A

alan

I think the OP means that he should do nothing and tomorrow
morning it works.

There's an article in the July 2005 C/C++UJ for a project called
NoodleGlue that bridges C++ to Java. Take a look.
 
R

Roedy Green

I know that if you call C++ from java, you have to use JNI. But how to
call Java from C++?

You use JNI. It is just a bit more complicated. I strongly recommend
buying a text on this one. The free docs are not adequate.

See http://mindprod.com/jgloss/jni.html


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
R

Roedy Green

T

tony_lincoln

I checked NoodleGlue, it is designed to provide Java access to their
native C and C++ libraries. But not to call java from C++ ...
 
J

jan V

I checked NoodleGlue, it is designed to provide Java access to their
native C and C++ libraries. But not to call java from C++ ...

I would appreciate it if you could answer my earlier question: if your C++
app is "huge and can't be changed", and does NOT already contain a
communication mechanism, then how do you expect any external entity to
provide a bridge to let your C++ app "call" Java methods?
 
S

Scott Ellsworth

I checked NoodleGlue, it is designed to provide Java access to their
native C and C++ libraries. But not to call java from C++ ...

I would appreciate it if you could answer my earlier question: if your C++
app is "huge and can't be changed", and does NOT already contain a
communication mechanism, then how do you expect any external entity to
provide a bridge to let your C++ app "call" Java methods?[/QUOTE]

I suspect the OP's code already has some kind of extension mechanism
that lets you drop in libraries, and he wants some magic would let him
write such a plugin from Java, but I am not quite sure.

Were I in that position, I might do an exec call that launches
appropriate Java code, then reads from files in the filesystem, or
perhaps over a socket.

Scott
 
Joined
Sep 21, 2009
Messages
2
Reaction score
0
Link to the latest JNI documentation

FYI, as of this post, the latest info on the Invocation API is available at java.sun.com/javase/6/docs/technotes/guides/jni/spec/invocation.html. The documentation has improved since Gordon Beaton posted his response.
 
Joined
Dec 1, 2011
Messages
2
Reaction score
0
how to run java app using c++

hi
i made a hardware for myself with ARM Micro controller and programed it with c++. .
now i want to run java portable device applications in my hardware. i mean .jar and .jad applications......
what should i do?????????????????????
(im about to change my micro controller and program it by c# - if it happens - how should i run java application???? .jar , .jad)
its better to email me your opinions too.....
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top