Commit 31ffff63 authored by Martin Deinhofer's avatar Martin Deinhofer
Browse files

migrated makefile.windows to support jdk8 and jdk10

moved jni/makefile.windows to root directory
adapted README.md to reflect new build commands (specifying the respective makefile)
modfied jni/HelloJNI.c to include java_exercises7_1_1_HelloJNI.h instead of HelloJNI.h
parent e1659571
......@@ -25,7 +25,9 @@ At times, it is necessary to use native codes (C/C++) to overcome the memory man
Building the project involves two steps
1. Building the Java code and the native code using the make targets:
* Command line:```make```
* **Linux**:```make -f makefile.linux all```
* **Windows**:```make -f makefile.windows all```
# Run project
......
#include <jni.h>
#include <stdio.h>
#include "HelloJNI.h"
#include "java_exercises7_1_1_HelloJNI.h"
// Implementation of native method sayHello() of HelloJNI class
JNIEXPORT void JNICALL Java_java_1exercises7_11_11_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
......
# Define a variable for classpath
CLASS_PATH = ./bin
JAVA_HOME=/usr/lib/jvm/default-java/
JNI_DIR=./jni
SRC_DIR=./src
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
all : $(JNI_DIR)/libhello.so $(JNI_DIR)/libjava_exercises7_2_1_HelloJNI.so
# Targets for java_exercises_7_1_1
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/libhello.so : $(JNI_DIR)/HelloJNI.o
gcc -W -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/HelloJNI.o : $(JNI_DIR)/HelloJNI.c $(JNI_DIR)/HelloJNI.h
gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I"$(JNI_DIR)" -c $< -o $@
# $* matches the target filename without the extension
$(JNI_DIR)/HelloJNI.h :
javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_1_1/HelloJNI.java
# Targets for java_exercises_7_2_1
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/libjava_exercises7_2_1_HelloJNI.so : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.o
gcc -W -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.o : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.c $(JNI_DIR)/java_exercises7_2_1_HelloJNI.h
gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I"$(JNI_DIR)" -c $< -o $@
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.h :
javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_2_1/HelloJNI.java
clean :
# Define a variable for classpath
CLASS_PATH = ./bin
JAVA_HOME=/usr/lib/jvm/default-java/
JNI_DIR=./jni
SRC_DIR=./src
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
all : $(JNI_DIR)/libhello.so $(JNI_DIR)/libjava_exercises7_2_1_HelloJNI.so
# Targets for java_exercises_7_1_1
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/libhello.so : $(JNI_DIR)/HelloJNI.o
gcc -W -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/HelloJNI.o : $(JNI_DIR)/HelloJNI.c $(JNI_DIR)/HelloJNI.h
gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I"$(JNI_DIR)" -c $< -o $@
# $* matches the target filename without the extension
$(JNI_DIR)/HelloJNI.h :
javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_1_1/HelloJNI.java
# Targets for java_exercises_7_2_1
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/libjava_exercises7_2_1_HelloJNI.so : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.o
gcc -W -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.o : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.c $(JNI_DIR)/java_exercises7_2_1_HelloJNI.h
gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I"$(JNI_DIR)" -c $< -o $@
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.h :
javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_2_1/HelloJNI.java
clean :
rm -Rf $(JNI_DIR)/*.h $(JNI_DIR)/*.o $(JNI_DIR)/*.so $(JNI_DIR)/*.dll $(CLASS_PATH)/*
\ No newline at end of file
# Define a variable for classpath
CLASS_PATH = ../bin
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_131
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
all : hello.dll java_exercises7_2_1_HelloJNI.dll
# Targets for java_exercises_7_1_1
# $@ matches the target, $< matches the first dependancy
hello.dll : HelloJNI.o
gcc -Wl,--add-stdcall-alias -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
HelloJNI.o : HelloJNI.c HelloJNI.h
gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -c $< -o $@
# $* matches the target filename without the extension
HelloJNI.h : java_exercises7_1_1/HelloJNI.class
javah -o HelloJNI.h -classpath $(CLASS_PATH) java_exercises7_1_1.$*
# Targets for java_exercises_7_2_1
# $@ matches the target, $< matches the first dependancy
java_exercises7_2_1_HelloJNI.dll : java_exercises7_2_1_HelloJNI.o
gcc -Wl,--add-stdcall-alias -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
java_exercises7_2_1_HelloJNI.o : java_exercises7_2_1_HelloJNI.c java_exercises7_2_1_HelloJNI.h
gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -c $< -o $@
java_exercises7_2_1_HelloJNI.h : java_exercises7_2_1/HelloJNI.class
javah -classpath $(CLASS_PATH) java_exercises7_2_1.HelloJNI
clean :
rm HelloJNI.h HelloJNI.o hello.dll java_exercises7_2_1_HelloJNI.dll java_exercises7_2_1_HelloJNI.h java_exercises7_2_1_HelloJNI.o
\ No newline at end of file
# Define a variable for classpath
CLASS_PATH = bin
# Either set JAVA_HOME as system-wide windows environment variable or set it here
#JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_131
JNI_DIR=jni
SRC_DIR=src
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
all : $(JNI_DIR)/hello.dll $(JNI_DIR)/java_exercises7_2_1_HelloJNI.dll
# Targets for java_exercises_7_1_1
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/hello.dll : $(JNI_DIR)/HelloJNI.o
gcc -Wl,--add-stdcall-alias -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/HelloJNI.o : $(JNI_DIR)/HelloJNI.c $(JNI_DIR)/HelloJNI.h
gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -I"$(JNI_DIR)" -c $< -o $@
# $* matches the target filename without the extension
$(JNI_DIR)/HelloJNI.h :
javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_1_1/HelloJNI.java
# Targets for java_exercises_7_2_1
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.dll : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.o
gcc -Wl,--add-stdcall-alias -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.o : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.c $(JNI_DIR)/java_exercises7_2_1_HelloJNI.h
gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -I"$(JNI_DIR)" -c $< -o $@
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.h :
javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_2_1/HelloJNI.java
clean :
rm -Rf $(JNI_DIR)/*.h $(JNI_DIR)/*.o $(JNI_DIR)/*.so $(JNI_DIR)/*.dll $(CLASS_PATH)/*
\ No newline at end of file
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