Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Eclipse Plug-in Development

You're reading from   Mastering Eclipse Plug-in Development Build modular applications on Eclipse by defining custom extension points and using OSGi services

Arrow left icon
Product type Paperback
Published in Aug 2014
Publisher
ISBN-13 9781783287796
Length 362 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Bandlem Limited Bandlem Limited
Author Profile Icon Bandlem Limited
Bandlem Limited
Alex Blewitt Alex Blewitt
Author Profile Icon Alex Blewitt
Alex Blewitt
Arrow right icon
View More author details
Toc

Native code and Eclipse


The Java Native Interface (JNI) is a standard way in which any Java program can interact with native code. The process for working with native code can be summarized as follows:

  1. Write a Java class with a native method.

  2. Compile the Java class as normal.

  3. Run javah with the class name, which generates a header stub.

  4. Write the native C function and export it with the given function signature.

  5. Compile the code into a dynamically linked library.

  6. Load the library into the runtime with System.loadLibrary.

  7. Execute the native method as normal.

The name of the library is dependent on the operating system; some call the library name.dll, some call it libname.so, and others libname.dylib. However, Java just uses the real portion of the library name; so, all three platforms use the same Java code, System.loadLibrary("name"), to load the library.

Creating a simple native library

For the purpose of this chapter, a native library will be created to perform a simple Maths operation class that...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image