How to add 'main/src/…/messages.properties' file to ShrinkWrap WebArchive?

余生长醉 提交于 2019-12-04 08:17:51
rubenlop88

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")

Now Maven copies my messages.properties to the directory target/test-classes. Therefore ShrinkWrap will find it in the classpath.

The trick in this case is to add resource as a File:

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!