0

Maven CLI Options Reference says -D option define a system property. The question is how to retrieve this option in Java Code.

I tried the following snippet and command, but couldn't retrieve it.

public class Test2Class {

    @Test
    public void test() {
        System.out.println((new Properties()).get("env"));
    }
}

mvn -Dtest=Test2Class test -Denv=dev

What else should I do to make it work?

niaomingjian
  • 3,472
  • 8
  • 43
  • 78
  • Possible duplicate of [How to pass java code a parameter from maven for testing](https://stackoverflow.com/questions/13245411/how-to-pass-java-code-a-parameter-from-maven-for-testing) – jannis Jul 17 '18 at 07:43
  • 1
    Can you clarify your question with more details ? What you wants to achieve exactly so far , – Ishita Shah Jul 17 '18 at 07:43

1 Answers1

0
Properties p = System.getProperties();
p.get("my.property");

or

System.getProperty("my.property")

Have a look here: How to pass java code a parameter from maven for testing

jannis
  • 4,843
  • 1
  • 23
  • 53