如何通过javah生成jni头文件

1.javah的使用说明:

 

-classpath 给出包含native接口的java类的.class文件路径

-d / –o 指定生成的头文件的,-d只给出文件不指定文件名, -o直接指定文件的路径给名字

-jni 给出包含native接口的java类的包名和类名

 

2.例子

2.1 java文件代码

 1 package com.eostek.serialport;
2
3 import java.io.FileDescriptor;
4
5 public class SerialPort {
6 static {
7 System.loadLibrary("serialport_jni");
8 }
9
10 public static native FileDescriptor open(String path, int baudrate);
11
12 public static native void close(FileDescriptor fd);
13 }

2.2 在终端先编译好java文件,然后通过javah生成jni头文件

例如:(路径根据实际项目修改)

javah -classpath ../../../out/target/common/obj/APPS/SerialPort_intermediates/classes/ -o jni/SerialPort.h -jni com.eostek.serialport.SerialPort

执行命令后 在当前目录的jni子目录生成一个SerialPort.h文件,文件内容如下:

/* DO NOT EDIT THIS FILE - it is machine generated */

#include <jni.h>

/* Header for class com_eostek_serialport_SerialPort */

#ifndef _Included_com_eostek_serialport_SerialPort

#define _Included_com_eostek_serialport_SerialPort

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class:     com_eostek_serialport_SerialPort

* Method:    open

* Signature: (Ljava/lang/String;I)Ljava/io/FileDescriptor;

*/

JNIEXPORT jobject JNICALL Java_com_eostek_serialport_SerialPort_open

  (JNIEnv *, jclass, jstring, jint);

/*

* Class:     com_eostek_serialport_SerialPort

* Method:    close

* Signature: (Ljava/io/FileDescriptor;)V

*/

JNIEXPORT void JNICALL Java_com_eostek_serialport_SerialPort_close

  (JNIEnv *, jclass, jobject);

#ifdef __cplusplus

}

#endif

#endif

jni javah的更多相关文章

  1. Android Studio JNI javah遇到的问题

    好久没写博客了.持之以恒的勋章也被收回了.以后要好好坚持.. 最近在学习jni,但是遇到了一点麻烦的问题.好在终于解决了,便记下来解决一下. 其他入门的jni文章有很多,这里便不在累赘,直接上我遇到的 ...

  2. jni.h头文件详解二

    作者:左少华 博客:http://blog.csdn.net/shaohuazuo/article/details/42932813 转载请注明出处:http://blog.csdn.net/shao ...

  3. 【转】 jni.h头文件详解(二)

    原文网址:http://blog.csdn.net/shaohuazuo/article/details/42932813 作者:左少华 博客:http://blog.csdn.net/shaohua ...

  4. 解决javah生成c头文件时找不到android类库的问题

    问题描述: cmd下面进入工程的bin/classes下面,执行 javah xxx.xxx.A 生成头文件, 一般来说都是可以成功执行的,但是如果xxx.xxx.A类里面引用了android类库里面 ...

  5. java native方法及JNI实例 (转)

    转自:http://blog.csdn.net/xw13106209/article/details/6989415 1.参考文献: http://blog.csdn.net/youjianbo_ha ...

  6. java native方法与JNI实现

    native方法定义: 简单地讲,一个Native Method就是一个java调用非java代码的接口.一个Native Method是这样一个java的方法:该方法的实现由非java语言实现,比如 ...

  7. ok6410 android driver(7)

    This article talk about how to test device driver on JNI. There are two ways to test the device driv ...

  8. ndk-gdb 对java/native code联合调试(升级版)

    之前写过一篇 关于android native 开发,调试的文章(http://www.cnblogs.com/yaozhongxiao/archive/2012/03/13/2393959.html ...

  9. java初探native

    最近碰见一个java中一个native关键字,不知道是干什么的,如下: public native String FileName(String strURL);     static{        ...

随机推荐

  1. 【1】按照Django官网,编写一个web app 创建project/配置数据库

    1. Creating a project From the command line, cd into a directory where you'd like to store your code ...

  2. virtual table(有180个评论)

    To implement virtual functions, C++ uses a special form of late binding known as the virtual table. ...

  3. [POJ 2279] Mr. Young's Picture Permutations

    [题目链接] http://poj.org/problem?id=2279 [算法] 杨氏矩阵与勾长公式 [代码] #include <algorithm> #include <bi ...

  4. 14. Longest Common Prefix[E]最长公共前缀

    题目 Write a function to find the longest common prefix string amongst an array of strings. If there i ...

  5. 参照实验室这边案例做一个简单的maven webapp项目

    流程 : 首先写出一个简单的前端页面. 之后写配置文件.dao.domain等等,注意这里可以使用generator进行自动配置 实验室这边配置文件如下: 其实主要的配置文件就分为6“个”. appl ...

  6. ROS-Solidworks转URDF

    前言:URDF建模很粗糙,而ros提供了支持sw转urdf的插件,可以使建模更精细化. 一.安装sw_urdf_exporter插件 sw_urdf_exporter插件网址:http://wiki. ...

  7. BZOJ 3674/BZOJ 3673 主席树

    思路: 主席树维护可持久化数组 剩下的就是普通的并查集了- //By SiriusRen #include <cstdio> #include <cstring> #inclu ...

  8. rel= "noopener"

    rel= "noopener" <a href= "https://www.xiaogezi.cn/" target= "_blank" ...

  9. 搭建svn服务器(ubuntu)

    ubuntu搭建svn服务器 环境:ubuntu 12.04.5 apt-get install subversion 找个目录作为svn的仓库 mkdir svn svnadmin create s ...

  10. java中静态,抽象,接口,继承总结

    (一).静态: 1.静态方法里只能访问静态变量,静态变量是类所特有的,所有类实例都作用同一个变量 静态随着类的加载而加载 (二). 抽象:抽象相当于接口,没有方法体,只定义方法,让子类实现,抽象类中可 ...