Search code examples
javaspringmaven

How to attach VM options for maven command line


how can I add an arguments in maven command line defined as VM option. In Intellij I have the configuration

java 11 -Djasypt.encryptor.password=xxx

That solution works perfectly when I am reading VM option using @Value annotation in configuration class.

@Value("${jasypt.encryptor.password}")
private String jasyptEncryptorPassword;

I am using following command mvn -Djasypt.encryptor.password=xx spring-boot:run But it failed to fetch with following error.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jasyptConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'jasypt.encryptor.password' in value "${jasypt.encryptor.password}"

Only for command java -jar is possible to attach VM options ?


Solution

  • You can attach VM options to the spring boot plugin as below:

    mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Djasypt.encryptor.password=xxx"
    

    check the docs for the plugin here: spring-boot-maven-plugin docs

    Another option would be to set it in the pom.xml

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <jvmArguments>
                -Djasypt.encryptor.password=xxx
            </jvmArguments>
        </configuration>
    </plugin>