How to call Java from C++?

Discussion in 'Java' started by tony_lincoln@yahoo.com, Aug 9, 2005.

  1. Guest

    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
     
    , Aug 9, 2005
    #1
    1. Advertising

  2. On 9 Aug 2005 05:55:39 -0700, wrote:
    > 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

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Aug 9, 2005
    #2
    1. Advertising

  3. Guest

    Are there any other better methods except JNI?
    Thanks a lot
    tony
     
    , Aug 9, 2005
    #3
  4. jan V Guest

    > 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..
     
    jan V, Aug 9, 2005
    #4
  5. Guest

    Unfortunately C++ program is huge and can not be changed. Is there any
    better solutions?Thank a lot.
     
    , Aug 9, 2005
    #5
  6. jan V Guest

    > 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?
     
    jan V, Aug 9, 2005
    #6
  7. Joan Guest

    "jan V" <> wrote in message
    news:FN8Ke.165664$-ops.be...
    >> 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?
    >

    I think the OP means that he should do nothing and tomorrow
    morning it works.
     
    Joan, Aug 9, 2005
    #7
  8. Joan Guest

    "jan V" <> wrote in message
    news:FN8Ke.165664$-ops.be...
    >> 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?
    >

    Sorry, I forgot, you can use pipes.
     
    Joan, Aug 9, 2005
    #8
  9. Guest

    On 2005-08-09, Joan <> wrote:
    >
    > "jan V" <> wrote in message
    > news:FN8Ke.165664$-ops.be...
    >>> 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?
    >>

    > 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.

    --
    Alan Gutierrez -
    - http://engrm.com/blogometer/index.html
    - http://engrm.com/blogometer/rss.2.0.xml
     
    , Aug 10, 2005
    #9
  10. Roedy Green Guest

    On 9 Aug 2005 05:55:39 -0700, wrote or quoted :

    >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
     
    Roedy Green, Aug 10, 2005
    #10
  11. Roedy Green Guest

    On 9 Aug 2005 12:01:19 -0700, wrote or quoted :

    >Are there any other better methods except JNI?
    >Thanks a lot


    If you just mean communication, you can talk via sockets, files,
    execing with parms.


    --
    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
     
    Roedy Green, Aug 10, 2005
    #11
  12. Guest

    I checked NoodleGlue, it is designed to provide Java access to their
    native C and C++ libraries. But not to call java from C++ ...
     
    , Aug 10, 2005
    #12
  13. jan V Guest

    > 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?
     
    jan V, Aug 10, 2005
    #13
  14. In article <5smKe.166080$-ops.be>,
    "jan V" <> wrote:

    > > 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?


    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

    --
    Scott Ellsworth

    Java and database consulting for the life sciences
     
    Scott Ellsworth, Aug 11, 2005
    #14
  15. jcadow

    Joined:
    Sep 21, 2009
    Messages:
    2
    Location:
    Beantown
    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.
     
    jcadow, Sep 21, 2009
    #15
  16. mrjm

    Joined:
    Dec 1, 2011
    Messages:
    2
    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.....
     
    mrjm, Dec 1, 2011
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bill sandner
    Replies:
    1
    Views:
    888
    iksrazal
    Jul 1, 2004
  2. Buu Nguyen

    RMI: remote call or local call

    Buu Nguyen, Sep 9, 2004, in forum: Java
    Replies:
    5
    Views:
    804
    Esmond Pitt
    Sep 17, 2004
  3. hasho

    call by address vs. call by value

    hasho, Feb 10, 2004, in forum: C Programming
    Replies:
    35
    Views:
    3,027
    E. Robert Tisdale
    Feb 11, 2004
  4. Replies:
    13
    Views:
    6,118
  5. system call and library call

    , Aug 22, 2005, in forum: C Programming
    Replies:
    7
    Views:
    3,032
    Jonathan Bartlett
    Aug 23, 2005
Loading...

Share This Page