【问题标题】:Add changelog file to classpath in spring boot在 Spring Boot 中将更改日志文件添加到类路径
【发布时间】:2021-09-08 13:43:34
【问题描述】:

在我的 Spring Boot 项目中,我有一个端点来读取我的 CHANGELOG.md 文件的内容。 我想从类路径中读取我的 CHANGELOG 文件,因为我的代码中有这样的内容:

ClassPathResource myChangeLogFile = new ClassPathResource("CHANGELOG.MD");

【问题讨论】:

    标签: spring-boot maven classpath


    【解决方案1】:

    您必须将其包含在生成的 JAR 文件中,或者将其放在默认包含在类路径中的目录中(如 src/main/resources)。

    要包含在 JAR 文件中,您可以按如下方式进行:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>${build-helper-maven-plugin.version}</version>
        <executions>
            <execution>
                <id>attach-artifacts</id>
                <phase>package</phase>
                <goals>
                    <goal>attach-artifact</goal>
                </goals>
                <configuration>
                    <artifacts>
                        <artifact>
                            <file>CHANGELOG.md</file>
                            <type>md</type>
                            <classifier>changelog</classifier>
                        </artifact>
                    </artifacts>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      相关资源
      最近更新 更多