Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

MaxProcessCount on a tomcat causes jna error #24

Open
Geschan opened this issue Aug 31, 2013 · 3 comments
Open

MaxProcessCount on a tomcat causes jna error #24

Geschan opened this issue Aug 31, 2013 · 3 comments
Labels

Comments

@Geschan
Copy link

Geschan commented Aug 31, 2013

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
Copy link
Owner

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
Copy link
Author

Geschan commented Sep 20, 2013

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
Copy link
Owner

Did you have the chance to try it yet ?

@zippy1978 zippy1978 added the bug label May 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants