将jni运行的代码移动到test里面。
This commit is contained in:
parent
205978c59f
commit
3d6a565452
4
pom.xml
4
pom.xml
@ -44,8 +44,8 @@
|
|||||||
<version>3.1.1</version>
|
<version>3.1.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>uncompress</id>
|
<id>buildJin</id>
|
||||||
<phase>install</phase>
|
<phase>compile</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>exec</goal>
|
<goal>exec</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.zeekling.cn.jni;
|
package com.zeekling.cn.jni;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* javac -encoding utf8 -h . JniTest.java
|
* javac -encoding utf8 -h . JniLoader.java
|
||||||
* gcc -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -fPIC -shared jniTestNative.c -o libJniTestNative.so
|
* gcc -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -fPIC -shared jniTestNative.c -o libJniTestNative.so
|
||||||
*/
|
*/
|
||||||
public class JniTest {
|
public class JniLoader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* native关键字,表明这个方法使用java以外的语言实现
|
* native关键字,表明这个方法使用java以外的语言实现
|
||||||
@ -14,12 +14,7 @@ public class JniTest {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
//加载jni库so
|
//加载jni库so
|
||||||
System.load(JniTest.class.getResource("/libJniTestNative.so").getPath());
|
System.load(JniLoader.class.getResource("/libJniTestNative.so").getPath());
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
//运行后,控制台打印出 hello world
|
|
||||||
new JniTest().say("hello world");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
21
src/main/native/com_zeekling_cn_jni_JniLoader.h
Normal file
21
src/main/native/com_zeekling_cn_jni_JniLoader.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||||
|
#include <jni.h>
|
||||||
|
/* Header for class com_zeekling_cn_jni_JniLoader */
|
||||||
|
|
||||||
|
#ifndef _Included_com_zeekling_cn_jni_JniLoader
|
||||||
|
#define _Included_com_zeekling_cn_jni_JniLoader
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* Class: com_zeekling_cn_jni_JniLoader
|
||||||
|
* Method: say
|
||||||
|
* Signature: (Ljava/lang/String;)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_com_zeekling_cn_jni_JniLoader_say
|
||||||
|
(JNIEnv *, jobject, jstring);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
@ -1,21 +0,0 @@
|
|||||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
|
||||||
#include <jni.h>
|
|
||||||
/* Header for class com_zeekling_cn_jni_JniTest */
|
|
||||||
|
|
||||||
#ifndef _Included_com_zeekling_cn_jni_JniTest
|
|
||||||
#define _Included_com_zeekling_cn_jni_JniTest
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
* Class: com_zeekling_cn_jni_JniTest
|
|
||||||
* Method: say
|
|
||||||
* Signature: (Ljava/lang/String;)V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_com_zeekling_cn_jni_JniTest_say
|
|
||||||
(JNIEnv *, jobject, jstring);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "com_zeekling_cn_jni_JniTest.h"
|
#include "com_zeekling_cn_jni_JniLoader.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -8,7 +8,7 @@ extern "C" {
|
|||||||
* Method: say
|
* Method: say
|
||||||
* Signature: (Ljava/lang/String;)V
|
* Signature: (Ljava/lang/String;)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_com_zeekling_cn_jni_JniTest_say(JNIEnv* env, jclass cls, jstring j_str) {
|
JNIEXPORT void JNICALL Java_com_zeekling_cn_jni_JniLoader_say(JNIEnv* env, jclass cls, jstring j_str) {
|
||||||
const char *c_str = NULL;
|
const char *c_str = NULL;
|
||||||
char buff[128] = { 0 };
|
char buff[128] = { 0 };
|
||||||
jboolean isCopy;
|
jboolean isCopy;
|
||||||
|
12
src/test/java/com/zeekling/cn/jni/JniLoaderTest.java
Normal file
12
src/test/java/com/zeekling/cn/jni/JniLoaderTest.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package com.zeekling.cn.jni;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class JniLoaderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSay() {
|
||||||
|
new JniLoader().say("hello world");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user