w.r.t.: https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#run.run-goal.parameter-details.main-class
If I set spring-boot:run.main-class like so:
mvn spring-boot:run -Dspring-boot.run.main-class=some.class
and then try to access it via System.getProperty in my Java code like so:
String className = System.getProperty("spring-boot.run.main-class");
I get a null. I would expect it to return some.class. This would align with the behavior of exec-maven-plugin when one uses its exec.mainClass property.
i.e. if I do:
mvn exec:java -Dexec.mainClass=some.class
and then do:
String className = System.getProperty("exec.mainClass");
it returns some.class
Comment From: wilkinsona
exec:java does not fork a new JVM and the execution is performed in the JVM in which Maven is running. This means that the system property that's set on the command line and passed to Maven's JVM is available during the execution of the main class. spring-boot:run forks a new JVM so system properties set in the Maven JVM are not available. If you use exec:exec, which forks a new process, to execute your Java program I believe you will see the same behavior as spring-boot:run.
I don't think we should do anything here as spring-boot:run, which forks a new JVM, is consistent with the behavior of exec:exec which also forks a new JVM.
Comment From: siddhsql
ok thanks for that clarification. i was actually quite puzzled why the property was not making it through because it should have nothing to do with spring. your explanation makes sense. is there any webpage that explains why someone would want to use spring-boot-maven-plugin to run an application vs. the exec-maven-plugin?
On Tue, Dec 5, 2023 at 4:04 AM Andy Wilkinson @.***> wrote:
exec:java does not fork a new JVM and the execution is performed in the same JVM as Maven. This means that the system property that's set on the command line is available during the execution of the main class. spring-boot:run forks a new JVM so system properties set in the Maven JVM are not available. If you use exec:exec, which forks a new process, to execute your Java program I believe you will see the same behavior as spring-boot:run.
I don't think we should do anything here as spring-boot:run, which forks a new JVM, is consistent with the behavior of exec:exec which also forks a new JVM.
— Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/38651#issuecomment-1840662348, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6NWEK7HSTN4OFIEBQNTBCTYH4EVHAVCNFSM6AAAAABAGXHSQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBQGY3DEMZUHA . You are receiving this because you authored the thread.Message ID: @.***>