JNI学习笔记(javah命令使用)

本文详细介绍了JNI中javah命令的使用,包括在不同JDK版本下的执行路径,以及如何处理不带包名和带包名生成头文件的示例。通过java代码示例和生成的C代码,展示了javah命令的实际应用。

一.javah命令使用

  • jdk1.6在工程的classes目录下执行,生成头文件
  • > javah com.study.resultfromc.MainActivity
    
  • jdk1.7在工程的src目录下执行,生成头文件

    > javah com.study.resultfromc.MainActivity
    

二.不带包名生成的结果

这里写图片描述

java代码

public class Test
{   
    public native int result_from_c(int a,int b);
    public native String hello();
}

生产的C代码

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

#ifndef _Included_Test
#define _Included_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Test
 * Method:    result_from_c
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_Test_result_1from_1c
  (JNIEnv *, jobject, jint, jint);

/*
 * Class:     Test
 * Method:    hello
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_Test_hello
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

带包名生成的结果

这里写图片描述

java代码

package com.study.test;

public class Test
{
    public native int result_from_c(int a,int b);
    public native String hello();
}

生产的C代码

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

#ifndef _Included_com_study_test_Test
#define _Included_com_study_test_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_study_test_Test
 * Method:    result_from_c
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_com_study_test_Test_result_1from_1c
  (JNIEnv *, jobject, jint, jint);

/*
 * Class:     com_study_test_Test
 * Method:    hello
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_com_study_test_Test_hello
  (JNIEnv *, jobject);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

The_Web3_社区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值