• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with System

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code fails to set a System property

Running the code I always get:
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alejandro Barrero wrote:The following code fails to set a System property

Running the code I always get:


That appears to be working to me. What were you expecting to happen ?

Edit. I just realised what you are saying. You get that output every time you run the program, but you were only expecting it the first time. You thought once it had been set the first time every subsequent time you ran it the value would already be set. Is that right ?
You need to distinguish between system properties and environment variables. They are not the same things. System properties apply only to the current JVM process. They are not saved as environment variables.
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not quite clear on what you are trying to accomplish, what I do suspect from following the flow in your code is that you want to get the value for the key property at runtime. This is done using the -Dkey=value flag while invoking your program at the command line.

The code to accomplish this feature is as follows:



And we invoke the application at the command-line as follows:

java -Dkey=dynamicProperty DynamicProperties

Output:

foo=dynamicProperty

But then again if that was not your intentions then Joanne Neal post is answer to your problem

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic