The challenge to use jni in a java application.
- Java installed (I used 32 bit version)
- Some Java IDE (I used IntelliJ IDEA)
- Some C++ IDE (I used CLion)
- Write a java class using native methods (eg. private native void doStuff())
- Create a .h file out of that java class file:
javah -classpath <PATH_TO_YOUR_CLASS_FILE_FOLDER> -d <DESIRED_.h_FILE_PATH> <CLASS_NAME>
- Import the .h file to your c++ project
- Make sure your environment loads jni properly (see fhnw_prcpp_jni/part_cpp/CMakeLists.txt)
- Implement the functions / methods as you wish to
cd <YOUR_.cpp_IMPLEMENTATION_FILE_FOLDER>
g++ -Wl,--add-stdcall-alias -I "<JAVA_32_BIT_HOME>\include" -I"<JAVA_32_BIT_HOME>\include\win32" -shared -o <DESIRED_.dll_FILE_PATH> <IMPLEMENTATION_FILE>
- Copy the newly created .dll to the root of your java project
- Run your java application using the native methods (and cheer)