1

I am trying to install Ghostscript on my Linux server so that Ghost4j's PDF Utilities can be used.

I installed Ghostscript with LinuxBrew and added the path to Ghostscript binary to $PATH. So after this point, I was getting the following error:

java.lang.UnsatisfiedLinkError: Unable to load library 'gs': Native library (linux-x86-64/libgs.so) not found in resource path 
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.<init>(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at org.ghost4j.GhostscriptLibraryLoader.loadLibrary(GhostscriptLibraryLoader.java:39)
at org.ghost4j.GhostscriptLibrary.<clinit>(GhostscriptLibrary.java:36)
at org.ghost4j.Ghostscript.initialize(Ghostscript.java:323)

At this step, it was able to load and execute to GhostscriptLibrary.

After doing some research, I added symlink ln -s path/to/Ghostscript/lib/libgs.so.9.22 /usr/lib/libgs.so following this thread Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory and this resolved the previous error but gave another error:

java.lang.NoClassDefFoundError: Could not initialize class org.ghost4j.GhostscriptLibrary at 
org.ghost4j.Ghostscript.initialize(Ghostscript.java:323)

The jar file (ghost4j-1.0.1.jar) containing the class GhostscriptLibrary is in the classpath and it works completely fine locally on my Mac.

I am using Ghostscript 9.22 and Ghost4j 1.0.1

Any help would be great :)

KenS
  • 30,202
  • 3
  • 34
  • 51
Celina
  • 21
  • 1
  • 5
  • Does the stack trace for the `NoClassDefFoundError` provide a wrapped exception? That's where I would look first for details about what is failing. Without more information, we would be shooting in then dark. – John Bollinger Feb 09 '18 at 19:25
  • A `NoClassDefFoundError` with message `Could not initialize class XYZ` means that the JVM has already tried and failed to perform static initialization on the class `XYZ`. In this case, the only static initialization in `GhostScriptLibrary` is the loading of the native library. Please restart whatever you are using to run your Java code and see what exception your code throws. – Luke Woodward Feb 09 '18 at 19:33
  • @LukeWoodward Yeah I think its an issue with loading the native library (using jna) as well because I think it didn't load the library correctly the first time give the unable to load library error, and then running it again gave the second error regardless. – Celina Feb 09 '18 at 20:12

1 Answers1

1

I was able to resolve the above error by uninstalling Ghostscript and reinstalling it with the instructions on this page http://www.linuxfromscratch.org/blfs/view/svn/pst/gs.html and set the environment variable LD_LIBRARY_PATH to include the path to the .so files.

It was an issue with not being about to correctly load the native library, which was causing the second error regardlessly.

Celina
  • 21
  • 1
  • 5