Stacked Q&A

retrive command line -D option in Java maven project
  • 0 voting
  • 2022-08-12 00:00

    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?

  • 2 219 0 0
첨부 파일
답변
총 2개의 답변이있습니다.
  • 답변일: 2022-08-12 00:00

    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

  • 0 0 채택된 답변 퍼블 채택!
Tages
    활동순위
    유저
      파트너사