![]() | This article has multiple issues. Please help improve it or discuss these issues on the talk page . (Learn how and when to remove these messages)
|
GIWS is a wrapper generator intended to simplify calling Java from C or C++ by automatically generating the necessary JNI code.
GIWS is released under the CeCILL license.
The following Java class does some simple computation.
packagebasic_example;importjava.lang.Math;publicclassMyComplexClass{publicMyComplexClass(){// the constructor}publiclongmyVeryComplexComputation(doublea,doubleb){returnMath.round(Math.cos(a)+Math.sin(b)*9);}}
GIWS gives the capability to call it from C++.
#include<iostream>#include"basic_example.hxx"#include<jni.h>JavaVM*create_vm(){JavaVM*jvm;JNIEnv*env;JavaVMInitArgsargs;JavaVMOptionoptions[2];args.version=JNI_VERSION_1_4;args.nOptions=2;options[0].optionString=const_cast<char*>("-Djava.class.path=.");options[1].optionString=const_cast<char*>("-Xcheck:jni");args.options=options;args.ignoreUnrecognized=JNI_FALSE;JNI_CreateJavaVM(&jvm,(void**)&env,&args);returnjvm;}usingnamespacebasic_example;usingnamespacestd;intmain(){JavaVM*jvm=create_vm();MyComplexClass*testOfMyClass=newMyComplexClass(jvm);cout<<"My Computation: "<<testOfMyClass->myVeryComplexComputation(1.2,80)<<endl;return0;}
To generate the binding, GIWS uses a XML declaration. GIWS will generate the JNI code to call the Java object.
<packagename="basic_example"><objectname="MyComplexClass"><methodname="myVeryComplexComputation"returnType="long"><paramtype="double"name="a"/><paramtype="double"name="b"/></method></object></package>