JNI - Getting Started
来源:互联网 发布:速达软件数据库密码 编辑:程序博客网 时间:2024/04/29 17:20
1. Create a class that declares the native method. HelloWorld.java
class HelloWorld{private native void print();public static void main(String[] args){new HelloWorld().print();}static{System.loadLibrary("HelloWorld");}}
2. Use javac to compile the program
javac HelloWorld.java
3. Use javah to generate header file
javah -jni HwlloWorld
4. Write the C implementation of the native method.
Create file HelloWorld.c, and write:
#include <jni.h>#include <stdio.h>#include "HelloWorld.h"JNIEXPORT void JNICALL Java_HelloWorld_print (JNIEnv *env, jobject obj){printf("Hello World!\n");return;}
5. Compile C code and generate native library
gcc -shared HelloWorld.c -fPIC -I /usr/lib/jvm/java-1.7.0-openjdk-amd64/include -I /usr/lib/jvm/java-1.7.0-openjdk-amd64/include/linux -o libHelloWorld.so
Notes:
-fPIC
6. Run the program using the java interpreter
Set current file to java classpath,
LD_LIBRARY_PATH=.export LD_LIBRARY_PATH
Run java program:
java HelloWorld
0 0
- JNI - Getting Started
- JNI官方文档翻译2-Getting Started
- Getting started
- Getting Started
- Getting Started
- Getting Started
- Getting Started
- getting started
- Getting Started
- Getting Started
- Getting Started
- Getting Started
- Resin Getting Started
- Getting Started with Smartphone
- [C1.1] Getting Started
- JBPM-Getting Started
- AJAX:Getting Started
- SiteMesh Getting Started
- vb
- 对Handler的理解
- tomcat运行一段时间后,org.apache.jk.common.ChannelSock报错java.lang.IndexOutOfBoundsExcept
- tableView 折叠效果
- oracle锁概念 与 v$parameter字段介绍
- JNI - Getting Started
- 对任意10个随机数求和(3)
- swift 微信支付接口实现
- mongodb3.0.3集群分片搭建
- Android测试详解_1-Best Practices for Testing-介绍
- 正则表达式(适用于oracle及linux)
- 零基础myeclipse下springBoot+maven+thymeleaf的开发(1)
- 哈希表及哈希表查找相关概念
- 关于Xutils网络请求重试的问题