Java – Maven Exec plugin with preview capabilities

Maven Exec plugin with preview capabilities… here is a solution to the problem.

Maven Exec plugin with preview capabilities

Compiling Java source code with —enable-preview is easy:

<!-- Enable preview features -->

But how can you run exec:java? Use

<!-- Exec plugin.. run with `mvn exec:java` -->

It still results in the following error:

An exception occured while executing the Java class. 
Preview features are not enabled for Main (class file version 59.65535). 
Try running with '--enable-preview'


The problem is exec: Java runs in the same Maven Java process, and it is not started with —enable-preview by default.

One way you can switch to exec:exec

instead, but still use exec:java, is to create an . mvn/jvm.config file that contains -- enable preview. You can put it in the root directory of the project and check it into git. Or create an MVN_OPS environment variable.


Related Problems and Solutions