• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JAVA 4 giving error for java.lang.Error: getenv no longer supported, use properties and -D instead:

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need to access env variables (System variables)
But for System.getenv("Path") it am getting

java.lang.Error: getenv no longer supported, use properties and -D instead: Path
at java.lang.System.getenv(System.java:689)

How do I access system variables in Java 4.

Regards,
Amol
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yeah. Java went through a silly phase where they deprecated access to environment variables -- and actually changed it to return an error. The reasoning being that not all OSes supported environment variables. This was, of course, undone later.

The easiest solution is to do what the message says. Change your shellscript to use the -D option to assign the environment value to a system property, and in the program, use the system property instead.

Henry
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or use a newer JVM, of course.
 
Marshal
Posts: 79984
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:Or use a newer JVM, of course.

Agree; are you using Java1.4 which was withdrawn the best part of 6 years ago?
 
lekurwale amol
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
Change your shellscript to use the -D option to assign the environment value to a system property, and in the program, use the system property instead.

Henry




Henry,
Could you give an example of how to do this?
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

lekurwale amol wrote:
Could you give an example of how to do this?



Please search the forums. This topic has come up before. For example, I just did a search for "system properties" and this was the first hit...

https://coderanch.com/t/178539/java-SCJA/certification/java-command-line-option-good

Henry
 
Yes, my master! Here is the tiny ad you asked for:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic