diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2015-08-05 07:46:02 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-08-21 13:30:08 (GMT) |
commit | 4476feac33a88942ebbe2d988c7db4a575de716f (patch) | |
tree | 71b32923e9c02897260ed17b988786207d2b0cda /Tests/JavaJavah | |
parent | f9865743ed942b1932d664d136a4ad505b724bf6 (diff) | |
download | CMake-4476feac33a88942ebbe2d988c7db4a575de716f.zip CMake-4476feac33a88942ebbe2d988c7db4a575de716f.tar.gz CMake-4476feac33a88942ebbe2d988c7db4a575de716f.tar.bz2 |
UseJava: Add support for javah tool
Add a `create_javah` API.
Diffstat (limited to 'Tests/JavaJavah')
-rw-r--r-- | Tests/JavaJavah/B.cpp | 10 | ||||
-rw-r--r-- | Tests/JavaJavah/B.java | 19 | ||||
-rw-r--r-- | Tests/JavaJavah/CMakeLists.txt | 20 | ||||
-rw-r--r-- | Tests/JavaJavah/HelloWorld2.java | 10 |
4 files changed, 59 insertions, 0 deletions
diff --git a/Tests/JavaJavah/B.cpp b/Tests/JavaJavah/B.cpp new file mode 100644 index 0000000..2666757 --- /dev/null +++ b/Tests/JavaJavah/B.cpp @@ -0,0 +1,10 @@ + +#include <jni.h> +#include <stdio.h> + +#include "B.h" + +JNIEXPORT void JNICALL Java_B_printName(JNIEnv *, jobject) +{ + printf("B\n"); +} diff --git a/Tests/JavaJavah/B.java b/Tests/JavaJavah/B.java new file mode 100644 index 0000000..d731f39 --- /dev/null +++ b/Tests/JavaJavah/B.java @@ -0,0 +1,19 @@ +class B +{ + public B() + { + } + + public native void printName(); + + static { + try { + + System.loadLibrary("B"); + + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load.\n" + e); + System.exit(1); + } + } +} diff --git a/Tests/JavaJavah/CMakeLists.txt b/Tests/JavaJavah/CMakeLists.txt new file mode 100644 index 0000000..83b0ad0 --- /dev/null +++ b/Tests/JavaJavah/CMakeLists.txt @@ -0,0 +1,20 @@ +project(helloJavah Java CXX) + +cmake_minimum_required (VERSION 2.6) +set(CMAKE_VERBOSE_MAKEFILE 1) + +find_package(Java COMPONENTS Development) +include (UseJava) + +# JNI support +find_package(JNI) + +add_jar(hello3 B.java HelloWorld2.java) +create_javah(TARGET B_javah CLASSES B CLASSPATH hello3) + +add_library(B SHARED B.cpp) +add_dependencies(B B_javah) + +target_include_directories(B PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + ${JAVA_INCLUDE_PATH} + ${JAVA_INCLUDE_PATH2}) diff --git a/Tests/JavaJavah/HelloWorld2.java b/Tests/JavaJavah/HelloWorld2.java new file mode 100644 index 0000000..faf7277 --- /dev/null +++ b/Tests/JavaJavah/HelloWorld2.java @@ -0,0 +1,10 @@ +class HelloWorld2 +{ + public static void main(String args[]) + { + B b; + b = new B(); + b.printName(); + System.out.println("Hello World!"); + } +} |