JNI方面的笔记(未完待续)
Microsoft?Windows?[版本?6.1.7600]
版權所有?(c)?2009?Microsoft?Corporation。保留所有權利。
C:\Users\toto>javah
用法:javah?[選項]?<類>
其中?[選項]?包括:
????????-help?????????????????輸出此幫助消息并退出
????????-classpath?<路徑>?????用于裝入類的路徑
????????-bootclasspath?<路徑>?用于裝入引導類的路徑
????????-d?<目錄>?????????????輸出目錄
????????-o?<文件>?????????????輸出文件(只能使用?-d?或
????????-jni??????????????????生成?JNI樣式的頭文件(默
????????-version??????????????輸出版本信息
????????-verbose??????????????啟用詳細輸出
????????-force????????????????始終寫入輸出文件
使用全限定名稱指定?<類>(例
如,java.lang.Object)。
C:\Users\toto>cd?F:\android\TestNativeCode\bin
C:\Users\toto>F:
F:\android\TestNativeCode\bin>javah?cn.itcast.TestNati
F:\android\TestNativeCode\bin>
?
?
?
一個例子:
package cn.itcast;
public class TestNative {
?/**
? * 通過jdk目錄下的javah.exe工具生成c/c++的頭文件
? *
? * 1、進入命令行。
? * 用法:javah [選項] <類>
???? *??? 其中 [選項] 包括:
???? *?? -help???????????????? 輸出此幫助消息并退出
???? *?? -classpath <路徑>???? 用于裝入類的路徑
???? *? -bootclasspath <路徑> 用于裝入引導類的路徑
???? *? -d <目錄>???????????? 輸出目錄
???? *? -o <文件>???????????? 輸出文件(只能使用 -d 或 -o 中的一個)
???? *? -jni????????????????? 生成 JNI樣式的頭文件(默認)
???? *? -version????????????? 輸出版本信息
???? *? -verbose????????????? 啟用詳細輸出
???? *? -force??????????????? 始終寫入輸出文件
???? *?
???? *? 2、找到TestNative.class文件,我的是存在:F:\android\TestNativeCode\bin\cn\itcast\TestNative.class
? *
? *? 3、通過如下的:
? *? C:\Users\toto>cd F:\android\TestNativeCode\bin
???? *
???? *C:\Users\toto>F:
???? *
???? *F:\android\TestNativeCode\bin>javah cn.itcast.TestNative
? *通過這些命令就可以在F:\android\TestNativeCode\bin目錄下生成一個cn_itcast_TestNative.h文件了,如下:。
? *
? ** DO NOT EDIT THIS FILE - it is machine generated *//*
? *?#include <jni.h>
? *?// Header for class cn_itcast_TestNative
? *?
? *?#ifndef _Included_cn_itcast_TestNative
? *?#define _Included_cn_itcast_TestNative
? *?#ifdef __cplusplus
? *?extern "C" {
? *?#endif
? *
? * Class:???? cn_itcast_TestNative
? * Method:??? sayHello
? * Signature: ()V
? *Java_包名_方法名。
? *
? *JNIEXPORT void JNICALL Java_cn_itcast_TestNative_sayHello
? * (JNIEnv *, jobject);
? *
? *#ifdef __cplusplus
? *?}
? *#endif
? *?#endif*/
?public native void sayHello();
?
?
?
?public static void main(String[] args) {
??
?}
}
?
?
第二個例子:
package democalldll;
/**
?* <p>Title: </p>
?* <p>Description: </p>
?* <p>Copyright: Copyright (c) 2010</p>
?* <p>Company: </p>
?* @author not attributable
?* @version 1.0
?*/
public class DemoCallDLLApp {
? static{
??? System.loadLibrary("test");
? }
? private native int showMsgBox_native(String str);
? public int showMsgBox(String str){
??? return showMsgBox_native(str);
? }
? public DemoCallDLLApp() {
? }
? public static void main(String[] args) {
??? DemoCallDLLApp demoCallDLLApp1 = new DemoCallDLLApp();
??? demoCallDLLApp1.showMsgBox("Call showMsgBox_native Successfully!");
? }
}
?
總結
以上是生活随笔為你收集整理的JNI方面的笔记(未完待续)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Cygwin,Nutch安装配置,检验是
- 下一篇: 全国2020年平均工资 对比一下看