It's not a secret anymore!
The moose likes Java in General and the fly likes Java call to C++ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java call to C++" Watch "Java call to C++" New topic

Java call to C++

chris baker

Joined: Apr 27, 2006
Posts: 1
I am writing a Web Crawler program and the GUI is written in Java. I am having trouble figuring out a way to call C++ from the GUI. I have text fields where the user can specify a search query and a starting URL in order to search. The GUI then needs to send that data to C++ as strings. I cannot figure out any system calls or whatever I need in order to call my C++ program. Any help would be greatly appreciated. Thanks in advance.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Have you looked into JNI?

I don't actually know anything about calling C++ from Java (I've only called COBOL personally) that's just an educated guess as to where a good place to start is.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Yes, JNI is the way to call C++ (or C) from Java. Search Web site for information and tutorials.

Most tutorial information tends to be about using C. You can write your C++ in a C-like way, and it will work fine. But do search out the C++-specific features of JNI, because they make things a bit tidier.

Typically, you will not be able to call your existing C++ code directly from Java. It is usual to end up writing a C++ wrapper around your existing C++ code, to give it a JNI-compatible interface.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I agree. Here's the link:
subject: Java call to C++
jQuery in Action, 3rd edition