使用maven-spring-boot-plugin时将classpath添加到SpringBoot命令行启动

holgip5t  于 5个月前  发布在  Spring
关注(0)|答案(2)|浏览(48)

当我运行spring Boot 应用程序时,我尝试向添加一个类路径,该应用程序使用以下命令运行

mvn spring-boot:run

字符串
我现在能够使用插入到字段中的自定义参数向我的maven测试添加一个类路径文件夹
然而,这种方法在使用mvn spring-boot:run运行应用程序时并不起作用

drkbr07n

drkbr07n1#

Spring Boot Maven Plugin产生了一个JVM,默认情况下,它将包括你的项目应该在类路径上的任何东西,例如。

  • ${project.build.outputDirectory}这包括类和资源
  • 在项目的POM中声明的依赖项

如果你需要向这个类路径添加东西,这个插件提供了以下功能:

  • addResources
  • 使用测试类路径

例如,如果你想将这个文件夹:/this/that/theother添加到classpath中,那么你需要如下配置spring-boot插件:

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

字符串
配置完成后,如果调用mvn spring-boot:run -X,您将看到附加文件夹包含在类路径的前面。
[DEBUG] forked process:/this/that/theother:.

9udxz4iz

9udxz4iz2#

如果你不想在https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#run.run-goal.parameter-details.directories上修改你的pom,你也可以从命令行使用用户属性
在2.5.0 +版本中

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

字符串
之前,您可以使用文件夹

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

相关问题