Skip to content

devfabiosilva/jni_tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JNI (Java Native Interface) tutorial for beginners

Introduction

This tutorial will brief explain to you how to create a simple resource access between your Java VM code and native OS

What you will learn:

  • Create a shared library in C containing simple basic functions and simple resource to access your system
  • Create your JNI library in C to access your shared library
  • Compile JNI shared library, access your custom class, throw an Exception or Throwable through native code
  • Integrate JNI to your Java or Kotlin
  • Create a documentation for C using Doxygen
  • Create a documentation for Java using Javadoc
  • Integrate tests

Create a shared library in C containing simple basic functions

To create a native library in your OS system you need:

  • Install a C compiler e.g.: gcc for unix system (Linux, Mac) or Visual Studio for Windows
  • Install the latest version of Java 8 or 11 in your machine
  • Clone this repository
  • Run Make to compile this source code
  • Run this example in your JVM

TODO ...

Compiling libraries

  • Just type
cd <YOUR_PROJECT>/src/main/util && make
  • To test your library
cd <YOUR_PROJECT>/src/main/util && make test

Cleaning compiled library

Just type in your src/main/util folder:

make clean

JNI and C library documentation

Sample example functions and used JNI functions are documented here

Contact

mailto: fabioegel@gmail.com

License

MIT

About

JNI (Java Native Interface) tutorial

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published