如何将"main/src/.../messages.properties"文件添加到ShrinkWrap WebArchive? [英] How to add 'main/src/.../messages.properties' file to ShrinkWrap WebArchive?
问题描述
我在一个项目中有以下文件:
I have the following files in a project:
com/example/module/Messages.java
com/example/module/messages.properties
使用ShrinkWrap.create(WebArchive.class, "test.war").addPackages(true, "com.example.module")
仅将Messages.java
添加到生成的存档中.如何添加messages.properties
?
Using ShrinkWrap.create(WebArchive.class, "test.war").addPackages(true, "com.example.module")
only adds Messages.java
to the generated archive. How can I add messages.properties
?
谢谢.
编辑.
我现在正在使用addAsResource
,但是它仅适用于test/resources
文件夹下的文件.如何使它与main/src
下的文件一起使用?是否有任何Maven配置?
I am using addAsResource
now but it only works for files that are under test/resources
folder. How can I make it work with files under main/src
? Is there any maven configuration for that?
目标是不复制文件.现在,我在main/src
下有一个文件,在test\resources
下有一个副本.
The goal is to not duplicate files. Right now I have one file under main/src
and a duplicate under test\resources
.
推荐答案
我终于将此配置添加到了我的POM中:
I finally added this configuration to my POM:
<build>
<testResources>
<testResource>
<directory>${basedir}/src/main/java/</directory>
<includes>
<include>**/*.properties</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>${basedir}/src/test/resources/</directory>
</testResource>
</testResources>
</build>
然后我将属性文件添加为:
Then I added the properties file with:
.addAsResource("com/example/module/messages.properties")
现在,Maven将我的messages.properties
复制到目录target/test-classes
.因此,ShrinkWrap将在类路径中找到它.
Now Maven copies my messages.properties
to the directory target/test-classes
. Therefore ShrinkWrap will find it in the classpath.
这篇关于如何将"main/src/.../messages.properties"文件添加到ShrinkWrap WebArchive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!