Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java call to C++

 
chris baker
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, JNI is the way to call C++ (or C) from Java. Search java.sun.com 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic