Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

advice on implementation

Thread view: 
K.Faw - 21 Jun 2007 19:04 GMT
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.
Nigel Wade - 22 Jun 2007 09:38 GMT
> I am working on a project that requires a java program running on a
> Linux box to operate in different environments using different jar
[quoted text clipped - 41 lines]
> 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.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Roedy Green - 22 Jun 2007 11:19 GMT
On Thu, 21 Jun 2007 11:04:08 -0700, "K.Faw"
<k.fawcett@microcontrol.com> wrote, quoted or indirectly quoted
someone who 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:

he easiest way to have platform specific code it is put each variant
in a jar and have Java web start select the appropriate jar.

see http://mindprod.com/jgloss/javawebstart.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.