I'd like to be able to set a property on the JVM using the -D
switch. If I do that, can I access it from my code? If yes, how?
views:
68answers:
3can `mykey` be any string?
Geo
2010-01-12 14:07:55
Try it out and check the link
Filip Ekberg
2010-01-12 14:09:33
@Geo, yes `mykey` can be any string. However, there are a number of properties already defined by default. There's a list of them in the Java documentation at this page. http://java.sun.com/javase/6/docs/api/java/lang/System.html
Glen
2010-01-12 14:11:24
+3
A:
Apart from System.getProperty
, there's also Integer.getInteger
and Boolean.getBoolean
, if you want to get an integral or boolean value instead. :-)
Chris Jester-Young
2010-01-12 14:10:01
+1
A:
and as a bonus:
System.setProperty("yourkey",yourValue); //works very well too
allows you to make sure the property is set if you want to test things
Peter
2010-01-12 15:00:53