PDFNet for Java: Can I change the temporary directory separately from Java's `java.io.tempdir`?

Question:
I am using the Apryse SDK with Java on Linux. Since I don’t have execution privileges in the /tmp directory that Java uses at runtime, I am receiving an UnsatisfiedLinkError when I attempt to run my application:

Exception in thread “main” java.lang.UnsatisfiedLinkError: /tmp/NativeLib13285533393718/libPDFNetC.so: /tmp/NativeLib13285533393718/libPDFNetC.so: failed to map segment from shared object
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1820)
at java.lang.Runtime.load0(Runtime.java:782)
at java.lang.System.load(System.java:1098)
at com.pdftron.pdf.NativeLoader.loadLibraryFromJar(NativeLoader.java:87)
at com.pdftron.pdf.PDFNet.(PDFNet.java:19)

Normally, I would alter the temp directory that Java uses by setting the Java environment variable java.io.tmpdir, however, I have other Java processes that rely on this being the temp directory. How can I run my application?

Answer:
The Apryse SDK has a Java environment variable that can be used in this situation called com.pdftron.systemloadtmpdir which works in the same way as setting java.io.tmpdir.

Usage Example:

// Assumes your application is called “App.java”
javac -cp .:…/…/…/Lib/PDFNet.jar App.java
java -cp .:…/…/…/Lib/PDFNet.jar -Dcom.pdftron.systemloadtmpdir=/newTmpDir App.java

Notes:

  • This predefined tmpdir was added in v10.11 of the Apryse SDK: patch notes.
  • Setting this temporary directory provides an alternative way to load the library when the user path contains Unicode characters that can prevent Java’s System.load() from working.
1 Like