maven资源导出问题

classpath:类路径,java和resourcees统称为classpath

这里一共创建了两个资源文件,resources路径下的db.properties和java路径下的cx.properties

然后我们来导出一下资源文件。

这是我们导出的文件:

resources路径下的db.properties被导出来了,但是java路径下的cx.properties没有被导出来。

maven由于约定大于配置,所以我们写的配置文件不按照maven的约定写的话会导致无法导出或则无法生效的问题。

解决方法:

在当前pom.xml下增加

<build>
        <resources>
<!--            设置正常情况的resources目录下的properties文件-->
            <resource>
<!--                配置路径-->
                <directory>src/main/resources</directory>
                <includes>
<!--                    包含什么文件-->
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
<!--      设置java路径的properties文件-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

配置完后重新生成一下

现在我们没有按照maven约定写的properties也能够成功导出。在maven约定之外的资源需要在pom.xml中进行配置。

posted @ 2021-05-30 15:15  时倾1001  阅读(594)  评论(0编辑  收藏  举报