users@glassfish.java.net

Calling the linux shell from Glassfish

From: <glassfish_at_javadesktop.org>
Date: Tue, 16 Oct 2007 11:50:37 PDT

Hi All,

So far so good, I got Glassfish to run and I'm following the tutorials in the book "Core JavaServer Faces", and the whole thing is making a bit more sense to me, but I'm still very new to this.

One of my main tasks here in France is to call up the Linux shell from Glassfish, so that various programs can be executed, but so far this is giving me a big headache, as I'm effectively working on my own and there is nobody around here who knows about this. I experimented with the "getRuntime()" method to call up the shell, and it appears to work when I call it from a Java program running in the console, but when called up in a Bean by Glassfish, I can only get some shell commands to work. It can create a folder and the code in Java can write to a file in that folder, but if I try something else, such as issuing a "cd" command, it won't work and reports an error. Is there a way to get any arbitrary string sent to the shell that can be invoked as a script? I'm aware of some of the pitfalls associated with using the "getRuntime()" method, and I have been using "try" and "catch".

As an alternative to this, I have also been experimenting with JNI, such that a string is passed to a short program in C, which then issues the "system()" function. After compiling the code in Java, creating the ".h" file, and compiling the code in C and linking in the shared library ".so" file, I got the code to work. The tricky bit was to remember to set the path with the "LD_LIBRARY_PATH" environment variable.

So far so good, but the problems arise when I want Glassfish to execute the code. I converted the Java code into a Bean, compiled it, compiled the code in C, and created the shared library as before, then created a ".war" file containing the ".class" and ".so" files, together with the regular ".html" and ".jsp" files, and copied it over to the "autodeploy" directory of Glassfish. However, when Glassfish attempts to execute the Bean it reported an error that it could not find the library. More specifically, the error was:

java.lang.UnsatisfiedLinkError: no CallSystem in the java.library.path

where "CallSystem" is my class in the shared library. Obviously it is not finding it. How do I ensure that Glassfish finds the shared library? Is there some script that sets up the environment variable when Glassfish is started, or is there a way of issuing a command like

"java -Djava.library.path=.[name of class]"

I would be most grateful if someone could kindly enlighten me on this. There must be many other people who want to invoke a shell from Glassfish.

csharpdotcom
[Message sent by forum member 'csharpdotcom' (csharpdotcom)]

http://forums.java.net/jive/thread.jspa?messageID=240479