A sample java program for interaction of java with native language such as C/C++ to create a pdf file.
- Run the following command to create header
PdfWriter.h
file with the native method declarations in it.
javac -h . Main.java
-
Use the header files and shared library from PDFWriter project to define the methods in
PdfWriter.h
header files. -
Run the following command to create a shared library to be used for java native interface
g++ -shared PdfWriter.cpp -I {Path to PDFWriter includes} -L {Path to PDFWriter shared library} -l pdfwriter -I JAVA_HOME/java-14-openjdk-amd64/include -I JAVA_HOME/java-14-openjdk-amd64/include/linux -o libpdf.so -fPIC
- Add the library generated
libpdf.so
to library path. - Running the java file
java Main