How to copy resource to src target directory with Maven?(如何使用 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目录下properties/下的所有属性文件时复制(否则程序会因为缺少配置文件而崩溃).
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
那么您不必添加资源元素.Maven默认将/src/main/resources 文件夹中的所有文件和文件夹复制到构建文件夹,并将它们定位在已编译类路径文件的根目录中.
例如,如果您在 /src/main/resources/configuration.properties
中有一个名为 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 目标目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Maven 将资源复制到 src 目标目录?
基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01