Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Setting a property for System.getProperty()

Reply
Thread Tools

Setting a property for System.getProperty()

 
 
RVic
Guest
Posts: n/a
 
      05-09-2013
I inherited someones mountain of code wherein they use different idioms and ways of doing things than I typically do.

In one instance, there is a line of code:

System.getProperty("cn.env");

which, depending on what machine it is run on, has properties like "production" or "mirror"

Yet, I think this call, System.getProperty(), calls properties from the actual system, like (System.getProperty("user.home") or System.getProperty("file.separator").

So how can I set this on a particular machine (Ubuntu 12 in this case) for a value for cn.env?

Thanks in advance, RVic
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      05-09-2013
On 5/9/2013 10:53 AM, RVic wrote:
> I inherited someones mountain of code wherein they use different idioms and ways of doing things than I typically do.
>
> In one instance, there is a line of code:
>
> System.getProperty("cn.env");
>
> which, depending on what machine it is run on, has properties like "production" or "mirror"
>
> Yet, I think this call, System.getProperty(), calls properties from the actual system, like (System.getProperty("user.home") or System.getProperty("file.separator").
>
> So how can I set this on a particular machine (Ubuntu 12 in this case) for a value for cn.env?


java -Dcn.env=ZaphodBeeblebrox MyClass

.... is one way. See also System.setProperty(), which you could
use in a "launcher" class like

public class Launcher {
public static void main(String[] args) {
// Get a value -- this takes one from the
// environment, but you could get as fancy
// as you like here.
String value = System.getenv("CN_ENV");

// Set the property.
System.setProperty("cn.env", value);

// Run the "real" main() method.
MyClass.main(args);
}
}

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
 
 
 
RVic
Guest
Posts: n/a
 
      05-09-2013
I need to set it outside of of the running application, so the -D option is what I need to invoke. However, THis is a war archive running under tomcat, started (in script) with:

sudo service tomcat-$SITE start

How would you invoke the -Dcn.env="mirror" in this?

Thanks for your help here guys! RVic
 
Reply With Quote
 
RVic
Guest
Posts: n/a
 
      05-09-2013
Well, apparently it IS being set, in /etc/init.d for that file I see:
---------------------------------
JVM_PARAM='-verbose:gc -XX:+PrintGCDetails -Dcn.instance=router -Dcn.env=mirror'

export JVM_PARAM

# Call the common script
/home/cnadmin/scripts/tomcat/tomcat.sh $1
----------------------------------------------------

So I guess it is being set here. I shall go back to the drawing board, apparetnyl what I believed to be the problem may not be the problem. Thanks for your help guys. RVic
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      05-09-2013
On 5/9/2013 9:14 AM, RVic wrote:
> Well, apparently it IS being set, in /etc/init.d for that file I
> see: --------------------------------- JVM_PARAM='-verbose:gc
> -XX:+PrintGCDetails -Dcn.instance=router -Dcn.env=mirror'
>
> export JVM_PARAM
>
> # Call the common script /home/cnadmin/scripts/tomcat/tomcat.sh $1
> ----------------------------------------------------
>
> So I guess it is being set here. I shall go back to the drawing
> board, apparetnyl what I believed to be the problem may not be the
> problem. Thanks for your help guys. RVic
>


Does this actually do anything? I don't think the jvm will treat the
JVM_PARAM variable in a special way. Google at least didn't seem to
come up with anything. So unless the JVM_PARAM is on the invocation
line to tomcat.sh, I don't think anyone is going to see these values.

You might try modifying the tomcat.sh script to dump its parameters to a
file where you can see them, just to verify what's being passed in to
the tomcat instance. There might be a better way too; maybe the ps
command can be induced to dump the command line of a running process.

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-10-2013
On 5/9/2013 12:01 PM, RVic wrote:
> I need to set it outside of of the running application, so the -D option is what I need to invoke. However, THis is a war archive running under tomcat, started (in script) with:
>
> sudo service tomcat-$SITE start
>
> How would you invoke the -Dcn.env="mirror" in this?


Typical you would set it in env variable JAVA_OPTS and
then catalina.sh would pick it up.

Arne


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-10-2013
On 5/9/2013 12:48 PM, markspace wrote:
> On 5/9/2013 9:14 AM, RVic wrote:
>> Well, apparently it IS being set, in /etc/init.d for that file I
>> see: --------------------------------- JVM_PARAM='-verbose:gc
>> -XX:+PrintGCDetails -Dcn.instance=router -Dcn.env=mirror'
>>
>> export JVM_PARAM
>>
>> # Call the common script /home/cnadmin/scripts/tomcat/tomcat.sh $1
>> ----------------------------------------------------
>>
>> So I guess it is being set here. I shall go back to the drawing
>> board, apparetnyl what I believed to be the problem may not be the
>> problem. Thanks for your help guys. RVic
>>

>
> Does this actually do anything? I don't think the jvm will treat the
> JVM_PARAM variable in a special way. Google at least didn't seem to
> come up with anything. So unless the JVM_PARAM is on the invocation
> line to tomcat.sh, I don't think anyone is going to see these values.
>
> You might try modifying the tomcat.sh script to dump its parameters to a
> file where you can see them, just to verify what's being passed in to
> the tomcat instance. There might be a better way too; maybe the ps
> command can be induced to dump the command line of a running process.


The JVM does certainly not do anything itself.

But that tomcat.sh may very well include JVM_PARAM in the
java command line.

For a standard Tomcat download from Apache the env var is
JAVA_OPTS and the script is catalina.sh (called from startup.sh).

Arne


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python-noob - which container is appropriate for later exportinginto mySql + matplotlib ? someone Python 45 04-15-2013 12:28 PM
GCC warnings for comma operator W Karas C Programming 16 04-12-2013 08:03 AM
Re: Message passing syntax for objects | OOPv2 Mark Janssen Python 1 04-12-2013 05:22 AM
Re: Message passing syntax for objects | OOPv2 Ethan Furman Python 0 04-12-2013 02:13 AM



Advertisments