0

I can't find anything on how to work with Java environments (production, development, etc) since every time I search for "java environment variables" I get results of how to install Java on windows and windows environment variables (JAVA_HOME) or similar things. Could someone explain how Java environments work and where to find official documentation?

To put you in context, I'm a junior developer and I want to set a few different paths for my embedded database depending on whether I'm in production or development. My project doesn't have anything from spring or maven.

To better explain myself, I will give an example. In javascript, you can create files like .env , .env.development, etc. And inside them you put key value pairs. You can then retrieve that in your code. It dynamically returns the value depending on whether you are in development or production. I'm looking to do the same thing in Java but in a simple way. Without having to use Spring as it is extremely advanced

15
  • Does this answer your question? Switch between Prod and Dev environment Commented Oct 16, 2022 at 10:23
  • This isn't a Java concept; are you using a framework which supports different settings for development/production/testing, or do you just want to know how to read an environment variable in Java? Commented Oct 16, 2022 at 10:26
  • 1
    System.getEnvironment is exactly what you want. You will have to pass different variables depending on which system you are on. Commented Oct 16, 2022 at 11:03
  • 1
    It returns things like java_home...but also things like my_db_pwd or (better) my_app_environment... ;) ..these you'd have to set on the according env./pass as cmd arguments/...(e.g. java ... MyApp -Dmy_env=prod;) Commented Oct 16, 2022 at 11:04
  • 1
    thanks, i will try to find more info on what you said. Commented Oct 16, 2022 at 11:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.