Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
homberghp opened this issue Nov 2, 2022 · 4 comments

Comments

@homberghp
Copy link

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
Copy link
Contributor

pzygielo commented Nov 2, 2022

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

@homberghp
Copy link
Author

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
Copy link
Contributor

pzygielo commented Nov 2, 2022

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
Copy link

andirady commented Jun 5, 2023

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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants