Home > Software design >  How to pass add-module to spring boot application?
How to pass add-module to spring boot application?

Time:12-13

I am using a maven dependency which require me to pass add-module during compilation and runtime as mentioned here.

Can someone let me know how can I pass --add-module option to a spring boot application during compilation and runtime? It will be good if I can control both compilation and runtime behaviour from the pom.xml.

CodePudding user response:

For compilation you can use the maven-copmiler-plugin in your build of your pom.xml.

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <parameters>true</parameters>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <source>14</source>
                    <target>14</target>
                    <compilerReuseStrategy>reuseSame</compilerReuseStrategy>
                    <compilerArgs>
                        <arg>--enable-preview</arg>
                        <arg>--add-modules=jdk.incubator.foreign</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

As you see I have included also the --enable-preview. In JDK14 as reported in JEPS 370 it is not needed since this is not a preview feature. But keep an eye on it since it might be needed in other jdk versions since in some versions this belongs in preview features.

As for runntime a spring-boot application is normally just a .jar executable file which you start with the normal java -jar myApp.jar command.

According to oracle documentation, the format of the command line is

To execute a JAR file:

java [options] -jar jarfile [args...]

So the command you want would be

java --add-modules jdk.incubator.foreign -jar myApp.jar
  • Related