mojohaus / exec-maven-plugin

Exec Maven Plugin
https://www.mojohaus.org/exec-maven-plugin/
Apache License 2.0
163 stars 96 forks source link

add third execution mode to enable jvm parameters such as --enable-preview #345

Open homberghp opened 1 year ago

homberghp commented 1 year ago

It appears not possible to add jvm parameters. A use case is to execute the built product in a maven project with special (e.g. --enable-preview) jvm parameters. The execution mode is similar to exec with an additional parameter (or parameters) to add jvm parameters, such that e.g. --enable-preview or -Xmx512 can be passed.

This would be useful for new features and would allow starting the maven project from the IDE (with a specific configuration).

pzygielo commented 1 year ago

Do you mean that using arguments, commandlineArgs for that purpose is not possible?

homberghp commented 1 year ago

Maybe it is my misunderstanding, but from the doc and the source code I infer that the command line arguments are passed to the program, as the args to public static void main(String[] args); The effect I am looking for is java ${jvmArgs} com.example.Main ${commandLineArgs}, such that this can expand to e.g. java --release 19 --enable-preview com.example.Main Hello John, where --release 19 and --enable-preview are jvmArgs and Hello John are commandlineArgs

pzygielo commented 1 year ago

This works for me

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>java</executable>
              <arguments>
                <argument>--enable-preview</argument>
                <argument>MyClass</argument>
                <argument>a</argument>
                <argument>b</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

Not sure which java recognizes --release switch - mine don't.

andirady commented 1 year ago

You can set the JVM args using MAVEN_OPTS environment variable. It's stated in the docs for the systemProperties properties: "A list of system properties to be passed. Note: as the execution is not forked, some system properties required by the JVM cannot be passed here. Use MAVEN_OPTS or the exec:exec instead. See the user guide for more information."