【问题标题】:Adding classpath to SpringBoot command line start when using maven-spring-boot-plugin使用 maven-spring-boot-plugin 时将类路径添加到 SpringBoot 命令行启动
【发布时间】:2018-01-24 09:21:08
【问题描述】:

我正在尝试在运行我的 Spring Boot 应用程序时添加一个类路径,该应用程序使用以下命令运行

mvn spring-boot:run

我目前能够使用插入到字段中的自定义参数将类路径文件夹添加到我的 maven 测试中

但是,这种方法不适用于运行应用程序 mvn spring-boot:run

【问题讨论】:

  • 错误是什么?
  • java有标准的-cp参数,对于maven,或许可以放到MAVEN_OPTS,不过我没试过。
  • 类路径文件夹是什么意思?如果您使用的是 maven,则应在 pom.xml 中声明依赖项。你想做什么?

标签: java spring maven spring-boot


【解决方案1】:

Spring Boot Maven Plugin 生成一个 JVM,默认情况下,它将包含您的项目所说的应该在类路径中的任何内容,例如

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

如果您需要向该类路径添加内容,该插件提供以下功能:

例如,如果您想将这个文件夹:/this/that/theother 添加到类路径中,那么您将配置 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] 分叉进程的类路径:/this/that/theother:...

【讨论】:

【解决方案2】:

如果您不想根据https://docs.spring.io/spring-boot/docs/current/maven-plugin/run-mojo.html 修改您的 pom,那么您也可以从命令行使用用户属性

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

【讨论】:

    猜你喜欢
    • 2017-11-23
    • 2018-03-18
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    相关资源
    最近更新 更多