zippy1978 / ghost4j

Java wrapper for Ghostscript C API + PS/PDF document handling API
http://www.ghost4j.org
GNU Lesser General Public License v3.0
64 stars 38 forks source link

MaxProcessCount on a tomcat causes jna error #24

Open Geschan opened 11 years ago

Geschan commented 11 years ago

Hello,

I tried to get help on Stackoverflow but it seems that nobody was able to solve my problem. So I'm asking my question here again.

See http://stackoverflow.com/questions/18441454/using-ghost4j-with-maxprocesscount-on-a-tomcat-causes-jna-error for details.

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.

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.

So I tried setMaxProcessCount(2); to allow my application to execute more than one task at a time. But if I'm trying to execute my task, Ghost4j throws this error: org.ghost4j.renderer.RendererException: java.lang.Exception: java.lang.NoClassDefFoundError: com/sun/jna/Structure

zippy1978 commented 11 years ago

Hi,

Sorry for the late reply. Concurrency is the main drawback of the Ghostscript API (you can read http://www.ghost4j.org/threadsafetyandmultithreading.html for more info).

The problem lies in the fact that for some reason : JNA jar is not on the classpath of the forked JVM. As I don't know how your Tomcat JVM, I can only give you the part performing the fork in Ghost4J : it lies in JavaFork.java, the method is charge of retrieving the current classpath id called getCurrentClasspath, if you put some logs in it, you should be able to see where the problem lies.

If you find a fix, a pull request is always welcomed :)

Regards, Gilles

Geschan commented 11 years ago

How about appending the urls from System.getProperty("java.class.path") to the StringBuilder in getCurrentClasspath? In my case the urls in System.getProperty("java.class.path") are different from the urls you get with Thread.currentThread().getContextClassLoader().

zippy1978 commented 10 years ago

Did you have the chance to try it yet ?