GIWS (software)
Jump to navigation
Jump to search
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template 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.
Example
The following Java class does some simple computation.
package basic_example;
import java.lang.Math;
public class MyComplexClass{
public MyComplexClass(){
// the constructor
}
public long myVeryComplexComputation(double a, double b){
return Math.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;
JavaVMInitArgs args;
JavaVMOption options[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);
return jvm;
}
using namespace basic_example;
using namespace std;
int main(){
JavaVM* jvm = create_vm();
MyComplexClass *testOfMyClass = new MyComplexClass(jvm);
cout << "My Computation: " << testOfMyClass->myVeryComplexComputation(1.2,80) << endl;
return 0;
}
To generate the binding, GIWS uses a XML declaration. GIWS will generate the JNI code to call the Java object.
<package name="basic_example">
<object name="MyComplexClass">
<method name="myVeryComplexComputation" returnType="long">
<param type="double" name="a" />
<param type="double" name="b" />
</method>
</object>
</package>
See also
- SWIG allows one to call C or C++ from higher level languages
References
External links
Categories:
- Articles with topics of unclear notability from August 2015
- All articles with topics of unclear notability
- Products articles with topics of unclear notability
- Articles needing additional references from August 2015
- All articles needing additional references
- Articles lacking sources from April 2024
- All articles lacking sources
- Articles with multiple maintenance issues
- Programming tools
- Cross-platform software
- Free computer programming tools
- Java platform
- All stub articles
- Computer programming tool stubs