How to pass the environment name while calling java program from unix script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass the environment name while calling java program from unix script?
# 1  
Old 01-10-2012
MySQL How to pass the environment name while calling java program from unix script?

Hi,
I'm trying to test one unix shell script in dev environment. But I'm not sure how to pass the environment in my java program calling code. I'm trying to use -DconsumerEnv="DEV" but unfortunately I get 'null' while trying to print the value from java class.
System.out.println("Environment: "+ System.getProperty("consumerEnv"));

This is the code I'm using to call the java program from my unix script:
Code:
java -Xms64m -Xmx256m -Djava.library.path=$MY_CLASSPATH -cp $MY_CLASSPATH <<class-name>> -DconsumerEnv=$consumerEnv

I have verified that the value of $consumerEnv is coming as DEV.

Can anyone please help?
Thanks in advance.


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 01-10-2012 at 05:12 AM.. Reason: code tags
# 2  
Old 01-10-2012
try this

Code:
 
java -Xms64m -Xmx256m -Djava.library.path=$MY_CLASSPATH -cp $MY_CLASSPATH <<class-name>> -DconsumerEnv="$consumerEnv"

# 3  
Old 01-10-2012
Try this,

Code:
java -Xms64m -Xmx256m -Djava.library.path="$MY_CLASSPATH" -cp "$MY_CLASSPATH" <<class-name>> -DconsumerEnv="$consumerEnv"

# 4  
Old 01-10-2012
How to pass the environment name while calling java program from unix script?

try this inside the script which may solve ur problem :

Code:
DconsumerEnv="$consumerEnv" 
export $DconsumerEnv  

java -Xms64m -Xmx256m -Djava.library.path="$MY_CLASSPATH" -cp "$MY_CLASSPATH" <<class-name


Last edited by Franklin52; 01-10-2012 at 09:20 AM.. Reason: Please use code tags for data and code samples, thank you
# 5  
Old 01-11-2012
Still no luck Smilie
I tried this:
Code:
java -Xms64m -Xmx256m -Djava.library.path=$MY_CLASSPATH -cp $MY_CLASSPATH <class name> -DconsumerEnv="$consumerEnv"
export $DconsumerEnv

---------- Post updated 01-11-12 at 02:54 AM ---------- Previous update was 01-10-12 at 04:40 AM ----------

I found the resolution: Smilie
swapping <<class-name>> & -DconsumerEnv will work.
See the corrected code below:
Code:
java -Xms64m -Xmx256m -Djava.library.path="$MY_CLASSPATH" -cp "$MY_CLASSPATH" -DconsumerEnv="$consumerEnv" <<class-name>>

Thanks everyone for helping!!!!!...Smilie

Last edited by Pramit; 01-11-2012 at 04:57 AM.. Reason: Updated with resolution
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Pass RegEx to java program in bash script

I can't seem to get this right. I've tried it every way imaginable using every trick I see on stackexchange and such. No luck. So nothing major here, something like: #!/bin/bash SEARCH="ARG1 ARG2 '((^EXACT$)|(.*InTheMiddle*)|(^AtBeginning*))'" java -cp /my/class/path MyClassName $SEARCH... (3 Replies)
Discussion started by: stonkers
3 Replies

2. Shell Programming and Scripting

Triggering UNIX Script from a JAVA program

Hi I am trying to implement one program, where JAVA needs to trigger the backend UNIX script. Tried with options like String cmdArray = {"/bin/ksh","-c","/SCRIPT_ABSOLUTE_PATH/sampleScript.ksh /FILE_ABSOLUTE_PATH Test_File.dat TEST E SFTP"} When I trigger the script from front end with... (1 Reply)
Discussion started by: karumudi7
1 Replies

3. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

4. Shell Programming and Scripting

how to execute a unix shell script from a java program

Hi All, well , i am facing this problem.. i have tried a few sample codes but there isn't any solution . could anyone please give a sample code as of how to do this... Please see the below details...and read the details carefully. I have written some code, logic is 1)from... (4 Replies)
Discussion started by: aish11
4 Replies

5. Shell Programming and Scripting

Call java program from shell and pass values

Hi All, Can anybody please help me with how can i call my java program from shell and also pass parameter along with it so that the program can interpret the value/int and update the database. Thanks in advance Neha (1 Reply)
Discussion started by: Neha Goyal
1 Replies

6. Shell Programming and Scripting

Calling Java Method from UNIX using shell script

Hi All, I need to call a java method from a shell script. I know we can use the command java ClassName to call the main method in it. But I need to call another method that is there in the class and pass an email to it. Can I use java ClassName.MethodName(email) Any help will be... (4 Replies)
Discussion started by: RahulK
4 Replies

7. UNIX for Dummies Questions & Answers

calling a script from java

HI I need to build a GUI where a button could execute a script in Solaris 8. I am working with Sun ONE Studio 7 Enterprice Edition. Thanks (1 Reply)
Discussion started by: javierelizabeth
1 Replies

8. Shell Programming and Scripting

pass parameter back to calling program

Hi all, I am running AIX version 4. I have a shell script that is calling another script. I want the called script to obtain a value and pass it back to the calling script. So far, I know that to pass a parameter to a called script is as such: sh proc2.sh $1 $2 etc. What I don't know how... (11 Replies)
Discussion started by: jthomas
11 Replies

9. Post Here to Contact Site Administrators and Moderators

Java Programming in UNIX Environment

A suggetion: Don't we need to start Java Programming in UNIX Environment Forum ? (1 Reply)
Discussion started by: cub
1 Replies

10. UNIX for Dummies Questions & Answers

Java program calling a UNIX command

I was wondering if it was possible to call a unix command directly from a Java program during run-time. This command could very very basic e.g. "ps -ef" returned as a string, all I need is a starting place so if anyone has any suggestion or examples I would be very grateful (2 Replies)
Discussion started by: QUartz Ite
2 Replies
Login or Register to Ask a Question