Commit 499b9b73 authored by Martin Deinhofer's avatar Martin Deinhofer
Browse files

restructured README and seperated Eclipse and command line usage

parent c0deee6f
# Exercise repository for Java Native Interface (JNI)
At times, it is necessary to use native codes (C/C++) to overcome the memory management and performance constraints in Java. Java supports native codes via the Java Native Interface (JNI). This repository contains a "Hello World" example for using the JNI which is based on this [tutorial](https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html).
# Prerequisites
1. **Java Development Kit >= 8**
2. **C/C++ Compiler**
* **[windows-only]**: Cygwin or MinGW on Windows ([Read "How to Setup Cygwin and MinGW](https://www3.ntu.edu.sg/home/ehchua/programming/howto/Cygwin_HowTo.html)
* GCC compiler and Makefile ([Read "GCC and Make"](https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html))
3. **Eclipse for Java Developers** with **C/C++ Development Tool (CDT) extension** installed ([Read "Eclipse CDT"](https://www3.ntu.edu.sg/home/ehchua/programming/howto/EclipseCpp_HowTo.html)).
# Clone project
```git clone https://es.technikum-wien.at/embedded_systems_public/Java-Exercises-7-JNI-HW-Interfacing.git```
# Create Eclipse project
1. *File/New/Project*
2. Select *General/Project* and click *Next*
3. Unselect *Use default location* and browse to cloned diretory, click *OK*
4. Enter *Project name* and click *Finish*
# Build project
Building the project involves two steps
1. Building the Java code and the native code using the make targets:
* **Linux**:```make -f makefile.linux all```
* **Windows**:```make -f makefile.windows all```
# Run project
Before the application can be run, you must provide the library path to the native library (Linux: ```libhello.so```, Windows: ```hello.dll```) file, if it is not located in the *current working directory*.
This can be done via the VM argument ```-Djava.library.path```. Right-click on the project and select *Run As/Run Configurations*, then select *Java Application*. In the *Main tab*, enter the main class "HelloJNI" and in *Arguments/VM Arguments*, enter ```-Djava.library.path=jni```. Finally click on *Run*.
You should see the output "Hello World!" displayed on the console.
## Command line
### Example 1
```java -Djava.library.path=jni -cp bin java_exercises7_1_1.HelloJNI```
### Example 2
```java -Djava.library.path=jni -cp bin java_exercises7_2_1.HelloJNI```
# Exercise repository for Java Native Interface (JNI)
At times, it is necessary to use native codes (C/C++) to overcome the memory management and performance constraints in Java. Java supports native codes via the Java Native Interface (JNI). This repository contains a "Hello World" example for using the JNI which is based on this [tutorial](https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html).
# Prerequisites
1. **Java Development Kit >= 8**
2. **C/C++ Compiler**
* **[windows-only]**: Cygwin or MinGW on Windows ([Read "How to Setup Cygwin and MinGW](https://www3.ntu.edu.sg/home/ehchua/programming/howto/Cygwin_HowTo.html)
* GCC compiler and Makefile ([Read "GCC and Make"](https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html))
3. **(optional) Eclipse for Java Developers** with **C/C++ Development Tool (CDT) extension** installed ([Read "Eclipse CDT"](https://www3.ntu.edu.sg/home/ehchua/programming/howto/EclipseCpp_HowTo.html)).
# Clone project
```git clone https://es.technikum-wien.at/embedded_systems_public/Java-Exercises-7-JNI-HW-Interfacing.git```
# Run project
Before the application can be run, you must provide the library path to the native library (Linux: ```libhello.so```, Windows: ```hello.dll```) file, if it is not located in the *current working directory*.
This can be done via the VM argument ```-Djava.library.path```.
Follow the instructions below for Eclipse or command line usage.
# Command line
## Build project
Building the project involves two steps
1. Building the Java code and the native code using the make targets:
* **Linux**:```make -f makefile.linux all```
* **Windows**:```make -f makefile.windows all```
## Run project
### Example 1
```java -Djava.library.path=jni -cp bin java_exercises7_1_1.HelloJNI```
### Example 2
```java -Djava.library.path=jni -cp bin java_exercises7_2_1.HelloJNI```
# Eclipse (optional)
## Create Eclipse project
1. *File/New/Project*
2. Select *General/Project* and click *Next*
3. Unselect *Use default location* and browse to cloned diretory, click *OK*
4. Enter *Project name* and click *Finish*
## Run project
Right-click on the project and select *Run As/Run Configurations*, then select *Java Application*. In the *Main tab*, enter the main class "HelloJNI" and in *Arguments/VM Arguments*, enter ```-Djava.library.path=jni```. Finally click on *Run*.
You should see the output "Hello World!" displayed on the console.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment