title: Using Ghost4j with MaxProcessCount on a tomcat causes jna error
body: <p>I'm trying to develop a web-service (based on jersey) which is converting a pdf document into jpeg images.
  I choosed GhostScript because I have good experiences with it and it's results (especially with embedet fonts). So I searched a way to use GhostScript with Java and found Ghost4j.</p>
  
  <p>So I put all the Ghost4j jars into my applications lib folder (also the jna.jar). In my first tests I encountered a problem with executing the task more than once, because jna throws an error when it's launched more than one time.
  So I put the jna.jar into the tomcat lib folder. That worked a littlebit better, but it only executed one task at a time. If I started another one at the same time, nothing happened. I just didn't seem to execute the other task.</p>
  
  <p>So I tried <code>setMaxProcessCount(2);</code> to allow my application to execute more than one task at a time. Here is my code:</p>
  
  <pre><code>private static void generateImages(String inputFile, String outputPath) throws IOException, RendererException, org.ghost4j.document.DocumentException {
          PDFDocument document = new PDFDocument();
          document.load(new File(inputFile));
          SimpleRenderer renderer = new SimpleRenderer();
          renderer.setMaxProcessCount(2);
          renderer.setResolution(150);
          renderer.setAntialiasing(4);
          System.setProperty("jna.library.path", "C:\\Program Files\\gs\\gs9.09\\bin\\");
          List&lt;Image&gt; images = renderer.render(document);
          for (int i = 0; i &lt; images.size(); i++) {
                  ImageIO.write((RenderedImage) images.get(i), "jpeg", new File(outputPath + File.separatorChar + (i + 1) + ".jpeg"));
          }
  }
  </code></pre>
  
  <p>But if I'm trying to execute my task, Ghost4j throws this error:</p>
  
  <pre><code>org.ghost4j.renderer.RendererException: java.lang.Exception: java.lang.NoClassDefFoundError: com/sun/jna/Structure
      at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:133)
      at PdfResource.ConversionTask.generateImages(ConversionTask.java:218)
      at PdfResource.ConversionTask.exec(ConversionTask.java:58)
      at PdfResource.Task.run(Task.java:86)
      at java.lang.Thread.run(Thread.java:724)
  Caused by: java.lang.Exception: java.lang.NoClassDefFoundError: com/sun/jna/Structure
      at gnu.cajo.invoke.Remote.invoke(Remote.java:594)
      at gnu.cajo.invoke.Remote.invoke(Remote.java:722)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
      at sun.rmi.transport.Transport$1.run(Transport.java:177)
      at sun.rmi.transport.Transport$1.run(Transport.java:174)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:724)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
      at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
      at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
      at com.sun.proxy.$Proxy165.invoke(Unknown Source)
      at gnu.cajo.invoke.Remote.invoke(Remote.java:565)
      at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:126)
      ... 4 more
  Caused by: java.lang.NoClassDefFoundError: com/sun/jna/Structure
      at org.ghost4j.renderer.SimpleRenderer.run(SimpleRenderer.java:68)
      at org.ghost4j.renderer.AbstractRemoteRenderer.remoteRender(AbstractRemoteRenderer.java:64)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at gnu.cajo.invoke.Remote.invoke(Remote.java:582)
      at gnu.cajo.invoke.Remote.invoke(Remote.java:722)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
      at sun.rmi.transport.Transport$1.run(Transport.java:177)
      at sun.rmi.transport.Transport$1.run(Transport.java:174)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      ... 1 more
  Caused by: java.lang.ClassNotFoundException: com.sun.jna.Structure
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 23 more
  </code></pre>
  
  <p>I guess that it has something todo with the additional JVM that Ghost4j is launching and it doesn't seem to use the same classpath that tomcat uses, but I'm not really a java expert and have no idea how to solve this problem.</p>