Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #23962 > unrolled thread
| Started by | RVic <rvince99@hotmail.com> |
|---|---|
| First post | 2013-05-09 07:53 -0700 |
| Last post | 2013-05-09 21:57 -0400 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
Setting a property for System.getProperty() RVic <rvince99@hotmail.com> - 2013-05-09 07:53 -0700
Re: Setting a property for System.getProperty() lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-09 16:22 +0100
Re: Setting a property for System.getProperty() Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-05-09 11:33 -0400
Re: Setting a property for System.getProperty() RVic <rvince99@hotmail.com> - 2013-05-09 09:01 -0700
Re: Setting a property for System.getProperty() Arne Vajhøj <arne@vajhoej.dk> - 2013-05-09 21:51 -0400
Re: Setting a property for System.getProperty() RVic <rvince99@hotmail.com> - 2013-05-09 09:14 -0700
Re: Setting a property for System.getProperty() markspace <markspace@nospam.nospam> - 2013-05-09 09:48 -0700
Re: Setting a property for System.getProperty() Arne Vajhøj <arne@vajhoej.dk> - 2013-05-09 21:57 -0400
| From | RVic <rvince99@hotmail.com> |
|---|---|
| Date | 2013-05-09 07:53 -0700 |
| Subject | Setting a property for System.getProperty() |
| Message-ID | <38d76348-f691-439f-b476-50eeb2908c14@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-09 16:22 +0100 |
| Message-ID | <LK2dnU_WKrStIhbMnZ2dnUVZ8qSdnZ2d@bt.com> |
| In reply to | #23962 |
On 09/05/13 15:53, 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?
>
> Thanks in advance, RVic
Well of course you can use System.setProperty("myprop", "myval");
Or ...
You can set properties when you start your application using the -D
command line switch.
something like
javac Foo.java
java -Dmyprop=myval Foo
in you code you can access these properties like so
System.getProperty("myprop");
This would return the String "myval"
HTH
lipska
--
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2013-05-09 11:33 -0400 |
| Message-ID | <kmgfd9$p13$1@dont-email.me> |
| In reply to | #23962 |
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
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | RVic <rvince99@hotmail.com> |
|---|---|
| Date | 2013-05-09 09:01 -0700 |
| Message-ID | <5201e2c5-8699-43f2-87b6-96c37bd16583@googlegroups.com> |
| In reply to | #23962 |
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
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-05-09 21:51 -0400 |
| Message-ID | <518c52bd$0$32115$14726298@news.sunsite.dk> |
| In reply to | #23965 |
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
[toc] | [prev] | [next] | [standalone]
| From | RVic <rvince99@hotmail.com> |
|---|---|
| Date | 2013-05-09 09:14 -0700 |
| Message-ID | <3b41a19c-9f4b-4061-9f87-659361e099c2@googlegroups.com> |
| In reply to | #23962 |
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
[toc] | [prev] | [next] | [standalone]
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2013-05-09 09:48 -0700 |
| Message-ID | <kmgjqq$ktf$1@dont-email.me> |
| In reply to | #23966 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-05-09 21:57 -0400 |
| Message-ID | <518c5409$0$32115$14726298@news.sunsite.dk> |
| In reply to | #23967 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web