views:

154

answers:

2

Hi,

Synopsis: When calling an executable that links to shared libraries from Java code on Tomcat, I get errors on Windows 2003 whereas the executable works great on a command prompt.

I wanted to do this in Linux, but, alas, got outvoted and have to implement it using Windows Server 2003. Here it goes,

I have a simple Java code running on Tomcat which, when it receives a "start" signal from another server has to run an external executable (written in C++, using shared library DLLs from OpenCV and ffmpeg) like so

    String cmd = "c:\\workspace\\process_video.exe -video " + filename;

    // Execute the command
    Process proc = null;
 try {
  proc = rt.exec(cmd);
 } catch (Exception e) {
  System.out.println("VA-> Exception thrown in running the command!");
  errorOut.append(e.getStackTrace().toString());  
 }

Now, when I run the command in process_video from a DOS command prompt, it works (doesn't matter which directory it's issued from). However, when it is run through the Tomcat->my Java code->rt.exec() chain, cmd doesn't get executed, although the exception doesn't get thrown. When I examine Windows event logs, I see an APPCHRASH event for process_video with Fault Module Name cv110.dll, which is one of the OpenCV DLLs I link from cmd.

One solution would be to stuff all the DLLs used in process_video into the tomcat\lib directory, but this hurts my programmatic sensibilities, so I want to know if there is a better way to solve this issue. What user does Tomcat use when running executables on Windows? Maybe I can give more privileges to that user? Should I add the DLL paths to Tomcat's configuration file?

Any help will be much appreciated,

Thanks!

Cuneyt

+1  A: 

This is a Windows problem, not a Tomcat problem. By default, Windows looks in %Path% for DLLs, which may not include the directory of the EXE file.

You can fix this by creating an empty file called process_video.exe.local in the same direcotry as the EXE ( i.e. c:\workspace )

You can also create a .manifest file, but this is a bit more complicated.

an0nym0usc0ward
+3  A: 

Add an entry in the PATH evironment variable that points to where your DLLs are. If this doesn't work for your app, you can try adding the entry to Tomcat's PATH. You have to modify the PATH variable of the process that will be loading the executable. Since your Java code probably shares a JVM (and hence a process) with the Tomcat executable, that will dictate which environment the PATH variable will need to be updated.

Kelly French
Kelly, I already have the DLL dirs in PATH (remember that I can actually run the executable from the command prompt). How do I add a directory to Tomcat's PATH variable?
recipriversexclusion
Duh, I had them on my user's PATH and not the system path. Once I put the DLL dirs there, problem went away. Silly question really.
recipriversexclusion
I've been there. Good luck.
Kelly French