有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在使用mavenspringbootplugin时向SpringBoot命令行start添加类路径

我试图在运行spring boot应用程序时添加一个类路径,该应用程序使用以下命令运行

mvn spring-boot:run

目前,我可以使用插入到字段中的自定义参数向maven测试添加一个classpath文件夹

但是,这种方法在运行应用程序时不起作用 mvn spring boot:运行


共 (2) 个答案

  1. # 1 楼答案

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

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

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

    例如,如果您想将这个文件夹:/this/that/theother添加到类路径,那么您可以按照如下方式配置spring引导插件:

    <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] Classpath for forked process: /this/that/theother:...