Passing environment variables to a JVM, in a platform-independent manner

后端 未结 3 974
离开以前
离开以前 2020-12-30 23:30

I\'m developing a J2EE application that runs in JBoss on a Windows Vista machine, but the application will end up on a Linux machine. Is there a way to pass in the value of

3条回答
  •  一个人的身影
    2020-12-31 00:12

    System.getenv() is platform-independent by itself. Using your above example, you can most certainly write

    String value = System.getenv("MY_ENV_VAR")
    

    and it will work on both Linux and Windows. No reason to wrap this into java system property. That said, the "platform-dependent" part of getenv() lies in the fact that different operating systems use different environment variables, like PATH on windows vs path on Linux. But as long as you're using your own variables and name them consistently (always uppercase, for example), you'll be fine.

提交回复
热议问题