如何使用Maven将资源复制到src目标目录?

编程入门 行业动态 更新时间:2024-10-27 08:27:03
本文介绍了如何使用Maven将资源复制到src目标目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在开发一个现有的项目,该项目有一个包含以下内容的pom.xml文件:

I'm currently working on an existing project which has a pom.xml file with the following:

<resources> <resource> <filtering>false</filtering> <directory>src</directory> <includes> <include>**/*.properties</include> </includes> </resource> </resources>

我在基本路径中有一个名为properties的目录,其中包含属性文件。我希望在我的src目录中打包属性/包含所有属性文件时复制(否则程序会因缺少配置文件而崩溃)。

I have in the base path a directory called properties which contains properties files. I want to copy when packaging all the properties files contains under properties/ in my src directory (otherwise the program will crash due to missing configuration files).

所以我的问题是:

我如何使用Maven包含不在src目录下的资源文件?

How can i, with Maven include resource files that are not located under src directory?

我试试这个但它似乎不起作用:

I try this one but it doesn't seem to work:

<resources> <resource> <filtering>false</filtering> <directory>src</directory> <includes> <include>**/*.properties</include> <include>../properties/**</include> </includes> </resource> </resources>

感谢您的帮助。

推荐答案

如果您的文件结构如下: 标准目录布局

If your file structure is like this: Standard Directory Layout

然后你不必添加资源elemt。 Maven通过默认将位于/ src / main / resources文件夹中的所有文件和文件夹复制到build文件夹中,并将它们定位在已编译的类路径文件的根目录中。 如果您有一个名为 configuration.properties 的文件位于 /src/main/resources/configuration.properties 中,那么当运行 mvn clean compile 此文件将被复制到 /target/classes/configuration.properties 所以如果删除该部分,文件将位于您想要的位置

Then you dont have to add the resources elemt. Maven copies by default all the files and folders that are located in your /src/main/resources folder to your build folder and locates them in the root of your compiled classpath files. if you have for example a file called configuration.properties located in /src/main/resources/configuration.properties then when running mvn clean compile this file will be copied to your /target/classes/configuration.properties So if you remove that part the files will be located where u want them

<resource> <filtering>false</filtering> <directory>src</directory> <includes> <include>**/*.properties</include> </includes> </resource>

更多推荐

如何使用Maven将资源复制到src目标目录?

本文发布于:2023-07-15 10:12:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   目标   目录   资源   Maven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!