javah生成jni头文件

本文介绍了如何生成JNI头文件,首先编写包含native方法的Java源码,接着使用javac编译Java文件,然后通过javah工具生成对应的C头文件,该头文件用于定义Javanative方法的C/C++实现。
摘要由CSDN通过智能技术生成


1. 生成步骤

  • 写Java源码(test.Java)
  • 编译Java(test.class)
  • 把类文件转换成C的头文件(包名+test.h)

1.1 写java文件test.java

package com.mytest;

public class test
{
    static {
        System.loadLibrary("testJni");
    }

    public static native int helloworld(String str);
}

1.2 编译java文件

命令行下编译:

javac test.java

1.3 生成jni头文件

使用javah生成jni头文件

javah -classpath E:\code\eclipse-project\test\src com.mytest.test

此处要注意-classpath 是package所在目录,之后跟的是package+类名(不带扩展名)

生成头文件:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_mytest_test */

#ifndef _Included_com_mytest_test
#define _Included_com_mytest_test
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_mytest_test
 * Method:    helloworld
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_com_mytest_test_helloworld
  (JNIEnv *, jclass, jstring);

#ifdef __cplusplus
}
#endif
#endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值