3

I thought both define the same - JVM properties, but there is obviously a difference between those two and I cannot find a clear explanation. If I use both in Jenkins Maven built, only properties set by -D are visible in Java application by System.getProperties(). Although MAVEN_OPTS should be passed to JVM as well. Seems like I am missing something.

Thx for the explanation.

Petr Beneš
  • 303
  • 3
  • 15

1 Answers1

2

MAVEN_OPTS is an environment variable that lets you pass parameters to the Java VM running Maven.

Thus, you can do things like set the heap and perm size using it (e.g. MAVEN_OPTS=-XX:MaxPermSize=256m).

In contrast, the -D parameter are command line parameters. Maven is already running in Java, so you wouldn't be able to control Java related parameters.

See this page for an explanation of command line parameters and MAVEN_OPTS.

Based on that, I'm guessing the reason why you don't see the variable is because it's being used as a JVM argument rather than a property.

Perhaps this answer will help you get them?

Community
  • 1
  • 1
Daniel Omoto
  • 2,431
  • 17
  • 15
  • 1
    I have already went through both links. But according to the documentation I would expect MAVEN_OPTS=-Dname=value to be same as java -Dname=value which would be accessible by System.getProperty("name") – Petr Beneš Aug 16 '16 at 07:22
  • Thanks for the clarification.. That reasoning sounds correct... When I set MAVEN_OPTS in my Jenkins and execute mvn help:system, I can see the parameter under System Properties.. I wonder if it's getting lost somehow on the way to your Java application. – Daniel Omoto Aug 16 '16 at 08:37
  • Dont get it. Its there when I try mvn help:system. Its there when I am starting application [ott-qa-test-custom-maven_opts] $ /usr/lib64/etnpol-sun-java-1.8.0/bin/java -Dseb.cra.ott.environment=DEV -Dtest=LoginTest -Dseb.caps.browserName=chrome, but its not there when I try to get properties from inside the app by System.getProperties(). Only -Dtest=LoginTest gets recognized somehow, because it must get digested by maven-surefire-plugin.. otherwise other test would run as well (although not seen in properties either). – Petr Beneš Aug 17 '16 at 08:25