17

Have anyone successfully managed to setup a combined Java/C++ project for Eclipse?

What I am trying to do is quite simple;

1) Compile my Java sources
2) Run Javah to create the JNI interface
3) Compile all the C/C++ sources
4) Link native shared library + package the JAR

Hints or even real projects which work are much welcome.

(Eclipse 3.5)

Pratik
  • 30,639
  • 18
  • 84
  • 159
ointment
  • 173
  • 1
  • 1
  • 4
  • This isn't really related to your question but I'm curious: do you need to use JNI/C++? If so, what for? Is it something Java NIO could do? – cletus Oct 26 '09 at 11:43
  • The JNI is a bridge between Java and some old crypto hardware, and the API for the device is only available as a c-library. Right now I have two eclipse projects, one for java classes and second for the native parts in C. Unnecessary, I think Eclipse should be able to do it in one. :/ – ointment Oct 26 '09 at 12:19

3 Answers3

7

http://www.cs.umanitoba.ca/~eclipse/8-JNI.pdf I think this is what you wanted.Maybe a little old.

dape
  • 565
  • 1
  • 8
  • 9
  • I don't see any Eclipse references in that document. For a general JNI overview, nothing beats [The Java Native Interface - Programmer's Guide and Specification](http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/jniTOC.html) from Oracle. As for @ointment's original problem (which I am currently experiencing), I think I'll just have to use a good old-fashioned command line interface (possibly via an Ant task) to build my C++/Java JNI projects. – StockB Jan 10 '13 at 18:50
5

This really sounds like a job for a build system, like ant. Simply configure your Java project to use the ant builder. You would still get the benefits of language specific support for your C++ and Java projects, and, one click build of the project.

alphazero
  • 27,094
  • 3
  • 30
  • 26
1

I'm using the ant cpptasks for realizing a JNI project with Eclipse only on Linux and Windows. It was some work to get it running with the MSVC (Windows) and the GNU C++ compiler (getting all compiler and linker flags properly since has been done with Visual Studio Magic before) but it was really worth it.

For generating the C++ Header with javah and all the other Tasks you mentioned Ant will probably be the tool of choice, too.

Daff
  • 43,734
  • 9
  • 106
  • 120