LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java in C++, and vice versa (JNI ?) (https://www.linuxquestions.org/questions/programming-9/java-in-c-and-vice-versa-jni-628409/)

Shautieh 03-16-2008 07:02 AM

Java in C++, and vice versa (JNI ?)
 
Hello !

I'm sorry but this post will be quite lengthy :p

I am part of a project (symphonic) which intends to bypass the shitty sonic stage so we can manage our musics on our sony audio players. To explain the problem, I'll make a quick historic :
- a first app was made in Java with basic features ;
- someone else made a library for winamp with more advanced features in c++ (and bound on windows) ;
- it was decided to modify this library so it would run on linux, but in the meantime the java program was upgraded to the point it has nearly as much features as this library now.

So, the problem now is that there are 2 internal projects which intend to do the same thing. It was decided that the c++ one would become the main project in the future, but the java one won't be stopped so it's like, twice as much work -_-

+/- of the java program : can be run on all system directly from the audio player disk
+/- of the c++ program : they absolutely want the project to work as an amarok plugin (or other audio players' plugins), so it seems a java program won't do.

The idea is, won't it be easier in the long run to chose only one language, and then use JNI or something (don't know anything about it as far as now) ?? And if yes, do you think it would be better to have the core in c++ and some sort of java launcher, or the core in java and a c++ interface to use it ?

I am thinking of a java core and a c++ interface for the plugins' purposes, but as I don't know much about JNI I'd like to know what you think about it :) Any suggestions are really welcome !


Thanks !

Simon Bridge 03-16-2008 07:30 AM

Have you considered just using gcj?
http://linux.die.net/man/1/gcj
http://www.gnu.org/software/gcc/java/
Quote:

GCJ is a portable, optimizing, ahead-of-time compiler for the Java Programming Language. It can compile Java source code to Java bytecode (class files) or directly to native machine code, and Java bytecode to native machine code.

ta0kira 03-16-2008 11:17 AM

I think your problem will be with linking, not actually the in-code tasks. Remember that C++ libs have compiler-dependent mangled names, so you might be better off giving the library a C API while retaining C++ internally.
ta0kira

Shautieh 03-16-2008 11:43 AM

Quote:

Originally Posted by Simon Bridge (Post 3090220)

It seems to compile the java classes into executable code, but how should it help me ? I don't know how to use it from within the c++ program then :(

Quote:

6.2 Is it possible to invoke GCJ compiled Java code from a C++ application?

Yes, GCJ 3.1 supports a CNI-based invocation interface as well as the traditional JNI invocation API. See the GCJ Manual for more details on how to use the CNI interface.
I could use CNI direcly then, maybe.. ?


@TaOkira : so you think the application core should be in c++, and I'll be able to make a java front end which can use it ? (via a C API ?)


edit: having searched about it a bit more, I think the best would be to continue the java program (so it can be launched almost anywhere), and use JNI or CNI (on the compiled java code or not.. ?) so it can be called by c or c++ code for the audio players plugins. I need to be sure this is doable though, but it should be the right path..


All times are GMT -5. The time now is 06:34 AM.