Book Image

Mastering Eclipse Plug-in Development

By : Alex Blewitt, Bandlem Limited
Book Image

Mastering Eclipse Plug-in Development

By: Alex Blewitt, Bandlem Limited

Overview of this book

Table of Contents (18 chapters)
Mastering Eclipse Plug-in Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Plugging in to JFace and the Common Navigator Framework
Index

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...