Java: Using *.jar libraries in my Qt Project
-
wrote on 7 Jul 2011, 12:29 last edited by
Hello People,
in the future I shall use a proprietary library - a *.jar file. The *.jar file is not open source and quite big, as I heard. At this moment I do not have access to that file. The *.jar file offers special methods, which I need.
Is there a possibility in Qt, where I can
@
#include <pathToJar> //or something wired like
#includejar <pathToJar> //or
#import <pathToJar>
@This is just a preventive question to react for further decisions just in time.
I have heard about QtJambi, but as far as I understood, this is for Java programmers, which want to use Qt? (The other way around)
Cheers Huck
-
wrote on 7 Jul 2011, 12:35 last edited by
This is more of a C++ question than Qt, but anyway, you should look at the "Java Native Interface":http://en.wikipedia.org/wiki/Java_Native_Interface
-
wrote on 7 Jul 2011, 12:38 last edited by
Calling a Java method from C++? No, this does not work, because C++ and Java run in different environments.
-
wrote on 7 Jul 2011, 12:43 last edited by
[quote author="dialingo" date="1310042338"]Calling a Java method from C++? No, this does not work, because C++ and Java run in different environments. [/quote]
Sure it works, you have the library running in the JRE (which you have to embed in your application using JNI) and pass calls back and forth..
-
wrote on 7 Jul 2011, 12:53 last edited by
dialingo, it will work :) as most close to Qt example project I can name Necessitas.
-
wrote on 7 Jul 2011, 13:26 last edited by
bq. Sure it works, you have the library running in the JRE (which you have to embed in your application using JNI) and pass calls back and forth..
Ok, but then the main program is Java and C++ is a subroutine doing some stuff for java and possibly calling other Java routines. But can you do
@
int main()
{
callAJavaMethod();
}@ -
wrote on 7 Jul 2011, 13:39 last edited by
dialingo, afair it is possible via jni. But not sure, it should be checked in jni documentation
-
wrote on 7 Jul 2011, 15:28 last edited by
Thank you very much. I'll engage myself in JNI.
@interested: Here you can access a detailed book about JNI: "JNI eBook":http://java.sun.com/docs/books/jni/download/jni.pdf -
wrote on 8 Jul 2011, 04:20 last edited by
sure we can done, i had already used jni, you can find jni.h file in your jdk, you better read documentation.
[quote author="dialingo" date="1310045183"]bq. Sure it works, you have the library running in the JRE (which you have to embed in your application using JNI) and pass calls back and forth..Ok, but then the main program is Java and C++ is a subroutine doing some stuff for java and possibly calling other Java routines. But can you do
@
int main()
{
callAJavaMethod();
}@[/quote]
9/9