[英]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
Using ShrinkWrap.create(WebArchive.class, "test.war").addPackages(true, "com.example.module")
only adds Messages.java
to the generated archive. 使用
ShrinkWrap.create(WebArchive.class, "test.war").addPackages(true, "com.example.module")
仅将Messages.java
添加到生成的存档中。 How can I add messages.properties
? 如何添加
messages.properties
?
Thanks. 谢谢。
Edit. 编辑。
I am using addAsResource
now but it only works for files that are under test/resources
folder. 我现在正在使用
addAsResource
但它仅适用于test/resources
文件夹下的文件。 How can I make it work with files under main/src
? 如何使它与
main/src
下的文件一起使用? Is there any maven configuration for that? 那有没有maven配置?
The goal is to not duplicate files. 目标是不重复文件。 Right now I have one file under
main/src
and a duplicate under test\\resources
. 现在我在
main/src
下有一个文件,在test\\resources
下有一个副本。
I finally added this configuration to my POM: 我终于将这个配置添加到了我的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")
Now Maven copies my messages.properties
to the directory target/test-classes
. 现在,Maven将我的
messages.properties
复制到目录target/test-classes
。 Therefore ShrinkWrap will find it in the classpath. 因此ShrinkWrap会在类路径中找到它。
You can use the addAsResource
method to add the file. 您可以使用
addAsResource
方法添加文件。 The method is defined here: https://github.com/shrinkwrap/shrinkwrap/blob/master/api/src/main/java/org/jboss/shrinkwrap/api/container/ResourceContainer.java#L86 该方法在此定义: https : //github.com/shrinkwrap/shrinkwrap/blob/master/api/src/main/java/org/jboss/shrinkwrap/api/container/ResourceContainer.java#L86
The trick in this case is to add resource as a File: 在这种情况下的技巧是将资源添加为文件:
addAsResource(new File("src/main/foobar.properties"), "foobar.properties"))
. addAsResource(new File("src/main/foobar.properties"), "foobar.properties"))
。
Otherwise it must exist in the classpath - see org.jboss.shrinkwrap.impl.base.container.ContainerBase.fileFromResource(String resourceName)
. 否则它必须存在于类路径中 - 请参阅
org.jboss.shrinkwrap.impl.base.container.ContainerBase.fileFromResource(String resourceName)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.