Modern C++17 wrapper for JNI:
Base Java Link API, without generated headers:
#include <scapix/link/java/object.h>
using namespace scapix::link::java;
void test_string()
{
auto str = object<SCAPIX_META_STRING("java/lang/String")>::new_object();
auto length = str->call_method<SCAPIX_META_STRING("length"), jint()>();
}
Same code using generated headers:
#include <scapix/java_api/java/lang/String.h>
using namespace scapix::java_api;
void test_string()
{
auto str = java::lang::String::new_object();
auto length = str->length();
}
Calling standard JDK functions with automatic type conversion:
#include <scapix/java_api/java/lang/System.h>
#include <scapix/java_api/java/util/Locale.h>
#include <scapix/java_api/java/text/DateFormatSymbols.h>
using namespace scapix::link::java;
using namespace scapix::java_api;
void test()
{
// C++ objects are automatically converted to and from corresponding Java types.
// This works for any type supported by scapix::link::java::convert<> interface,
// which supports many STL types and can be extended for your own types.
std::string version = java::lang::System::getProperty("java.version");
std::vector<std::string> languages = java::util::Locale::getISOLanguages();
std::vector<std::vector<std::string>> zone_strings = java::text::DateFormatSymbols::getInstance()->getZoneStrings();
std::map<std::string, std::string> properties = java::lang::System::getProperties();
}
See more in Java Link example project:
$ git clone https://github.com/scapix-com/example2
$ cd example2
$ ./default.sh