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.hfile 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.hheader 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.soto library path. - Running the java file
java Main