advice on implementation

K

K.Faw

I am working on a project that requires a java program running on a
Linux box to operate in different environments using different jar
files. Here is the flow:
1)java RMI app (call it jRMI) is running on linux box (started by
daemon). jRMI's remote method receives two strings strE and strJ -
strE is the name of a shell script file that sets the environment need
to execute a 2nd java program jTCPIP(to be defined below) and strE is
a jar file name to be used when executing jTCPIP.

2) Windows C++ app (call winApp) ultimately communicates with jTCPIP
via a socket opened by jTCPIP, but the environment jTCPIP executes in
and the jar file it uses can change. So, first winApp retrieves the
appropriate strE and strJ from a DB and calls jRMI's remote object
passing it these names.

3) jRMI's remote object receives strE and strJ and calls a script file
(myscript) passing it these two strings as arguments.
java code:
String bashCmd="bash " + "myscript " + strJ + " " strE;
Process proc=Runtime.getRuntime().exec(bashCmd);

4) the script file first executes the file specified by strE (sets
paths etc.) then it executes the jTCPIP program with the jar file
specified by strJ.

5)jTCPIP, once started, opens a socket and communication is
established between jTCPIP and winAPP.

winAPP----->(strE strJ)------>jRMI ()----->(strE,strJ)----
myscript-------->execute strE script (sets env)
|
|-------->"java -classpath strJ jTCPIP" ---
|-------------------------------->( tcpip link between winApp and
jTCPIP)<-------------------------------------------------|

The problem I am seeing is that environments set by the execution of
strE script are not "seen" by jTCPIP (I can't think of a better word,
but ,for example, if JPATH is defined by an export statement in strE
("export JPATH=/home") jTCPIP does not know this definition).

I hope this explanation is clear enough. I can clarify any points as
needed, but I wanted to keep this as concise as possible. I'm looking
for a) advice on how to get jTCPIP to use environments set from
environment script strE OR b) recommendations on a better way to
implement this.
 
N

Nigel Wade

K.Faw said:
I am working on a project that requires a java program running on a
Linux box to operate in different environments using different jar
files. Here is the flow:
1)java RMI app (call it jRMI) is running on linux box (started by
daemon). jRMI's remote method receives two strings strE and strJ -
strE is the name of a shell script file that sets the environment need
to execute a 2nd java program jTCPIP(to be defined below) and strE is
a jar file name to be used when executing jTCPIP.

2) Windows C++ app (call winApp) ultimately communicates with jTCPIP
via a socket opened by jTCPIP, but the environment jTCPIP executes in
and the jar file it uses can change. So, first winApp retrieves the
appropriate strE and strJ from a DB and calls jRMI's remote object
passing it these names.

3) jRMI's remote object receives strE and strJ and calls a script file
(myscript) passing it these two strings as arguments.
java code:
String bashCmd="bash " + "myscript " + strJ + " " strE;
Process proc=Runtime.getRuntime().exec(bashCmd);

4) the script file first executes the file specified by strE (sets
paths etc.) then it executes the jTCPIP program with the jar file
specified by strJ.

5)jTCPIP, once started, opens a socket and communication is
established between jTCPIP and winAPP.

winAPP----->(strE strJ)------>jRMI ()----->(strE,strJ)----
|
|-------->"java -classpath strJ jTCPIP" ---
|-------------------------------->( tcpip link between winApp and
jTCPIP)<-------------------------------------------------|

The problem I am seeing is that environments set by the execution of
strE script are not "seen" by jTCPIP (I can't think of a better word,
but ,for example, if JPATH is defined by an export statement in strE
("export JPATH=/home") jTCPIP does not know this definition).

I hope this explanation is clear enough. I can clarify any points as
needed, but I wanted to keep this as concise as possible. I'm looking
for a) advice on how to get jTCPIP to use environments set from
environment script strE OR b) recommendations on a better way to
implement this.

Most likely this is not a Java problem but a shell problem, and you are not
executing "strE" correctly in your shell. To set environment variables in a
shell using a script you must execute that script in the context of the shell,
and not invoke a sub-shell. In bash you do this with the "." or source
built-in, i.e. ". script" or "source script". If you just run "script" it will
execute in a sub-shell and set the environment variables in that sub-shell but
not in the parent shell.

As an alternative, and to bring it into the Java domain, you could create an
array of environment variables in Java rather than use a script. Then you can
use the Runtime.exec(String command, String[] envp) method, where envp
specifies the environment for the command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top