Running PDFNet for JAVA on Mac OS X, Linux

Q: I have some problems runing PDFNetC in JAVA

compile:
javac -classpath .:/Users/garyl/Sites/test/pdfsearch/lib/PDFNetC/Lib/
PDFNet.jar PDFSearch.java

run:
java -classpath .:/Users/garyl/Sites/test/pdfsearch/lib/PDFNetC/Lib/
PDFNet.jar PDFSearch "google file system" "150" "page" /Users/garyl/
Sites/test/pdfsearch/input/input.pdf /Users/garyl/Sites/test/
pdfsearch/
output
(After PDFSearch, there are parameter for the search. Don't worry
them)

error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no
PDFNetC
in java.library.path
  at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1753)
  at java.lang.Runtime.loadLibrary0(Runtime.java:822)
  at java.lang.System.loadLibrary(System.java:993)
  at pdftron.PDF.PDFNet.<clinit>(PDFNet.java:17)
  at PDFSearch.main(PDFSearch.java:145)

line 145 is PDFNet.initialize(); I guess it cannot find the library.

Download link of the code:
http://gary.liang.cs.research.googlepages.com/pdfsearch.tgz
--------

Are you able to run any of the JAVA samples? (‘cd /PDFNet/Samples’,
then ‘sh runall_java.sh’).

It is most likely that Java can’t find the shared library.


If you are developing using JAVA on MAC OS X →

On Mac OS X, there is a weird naming convention (which is different
from Linux) - Java shared libraries must have an extension “.jnilib”
instead of “.dylib”. In case of PDFNet, the same shared library is
used for both JAVA and C/C++ development. In case you are developing
using Java on Mac, you can copy and rename libPDFNet.dylib into
libPDFNet.jnilib.

To let Java know about the library, you can either pass in the path
with the -Djava.library.path option or by copying ‘libPDFNet.jnilib’
into /Library/Java/Extensions/.


If you are developing using JAVA on LINUX →

Setting LD_LIBRARY_PATH for my test project seems to do the trick:

LD_LIBRARY_PATH=/PDFNet/Lib/:$LD_LIBRARY_PATH
java -classpath .:/PDFNet/Lib/PDFNet.jar MyTest

For more info, please search “LD_LIBRARY_PATH” on the Net.
In case you would like to avoid setting the “LD_LIBRARY_PATH”, you may
want
to copy the shared library to a standard search path for shared
libraries
(e.g. ‘/usr/local/lib’). There are other options, such as using
‘rpath’ etc.