flipkart

Tuesday, May 20, 2014

JNI Development using eclipse

Hi, every body knows programming of C language so they write already code in C language. This post i will try explain how to use C function in Java using eclipse.Following explain is based on Ubuntu operating system


First create java project 


File -> New -> Java Project

After created java project add java source file

right click on src folder select New->class

Write java source code file and save it

Right click on project folder select new -> folder

Give folder name as jni after press finish

Once press build project

Right click on project press Build project

Next go Run -> External tool configurations 

It's opened one window select program next click new 

Location field is javah exceutable file path

working directory is present project bin folder

Arguments is "-jni -classpath ${workspace_loc:/Hello/bin} -d ${workspace_loc:/Hello/jni} Hello " 

it's created java header file inside jni folder use that file for creation c source file before that one move C/C++ perspective

Right click on project New -> Other -> Convert to a C/C++ Project 

After selecting press Next inside select C project or C++ project after Shared library next press finish button

Before writing C source code right click project select Build Path -> Configure Build Path after it opend window inside window 

C/C++ Build -> Settings ->Includes -> select New after give path /usr/lib/jvm/java-6-openjdk/include

Next press OK button and Create New C source file using java Header file

After Build C/C++ perspective next return Java perspective

Once Build project

Right click project Run as -> Run Configurations 

Select inside Java Application -> project name -> Arguments -> 

Field VM arguments -Djava.library.path=$UR_PATH/project_name/Debug/

No comments:

Post a Comment