简体   繁体   中英

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?

You can attach the 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

Other 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM