Johng
Johng

Reputation: 101

Adding classpath to SpringBoot command line start when using maven-spring-boot-plugin

I'm trying to add a classpath to when I run my spring boot application, which is run with the following command

mvn spring-boot:run

I'm currently able to add a classpath folder to my maven tests, using custom arguments which inserted into the field

However this approach has not worked for running the application with mvn spring-boot:run

Upvotes: 5

Views: 16323

Answers (2)

Chris DaMour
Chris DaMour

Reputation: 4020

if you dont want to modify your pom per https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#run.run-goal.parameter-details.directories there are user properties too you can use from command line

in version 2.5.0 +

mvn -Dspring-boot.run.directories=/etc/bbcom spring-boot:run

prior you could use folders

mvn -Dspring-boot.run.folders=/etc/bbcom spring-boot:run

Upvotes: 5

glytching
glytching

Reputation: 47985

The Spring Boot Maven Plugin spawns a JVM which will, by default, include whatever your project says should be on the classpath e.g.

  • ${project.build.outputDirectory} this includes classes and resources
  • dependencies declared in your project's POM

If you need to add things to this classpath, the plugin offers the following:

For example, if you want to add this folder: /this/that/theother to the classpath then you would configure the spring-boot plugin as follows:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <folders>
            <folder>
                /this/that/theother
            </folder>
        </folders>
    </configuration>
</plugin>

With that configuration in place, if you invoke mvn spring-boot:run -X you'll see that the additional folder is included on the front of the classpath ...

[DEBUG] Classpath for forked process: /this/that/theother:...

Upvotes: 8

Related Questions