Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. How can I add messages.properties?

Thanks.

Edit.

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?

The goal is to not duplicate files. Right now I have one file under main/src and a duplicate under test\resources.

like image 927
rubenlop88 Avatar asked Sep 02 '13 16:09

rubenlop88


2 Answers

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.

like image 173
rubenlop88 Avatar answered Nov 15 '22 05:11

rubenlop88


You can use the addAsResource method to add the file. The method is defined here: https://github.com/shrinkwrap/shrinkwrap/blob/master/api/src/main/java/org/jboss/shrinkwrap/api/container/ResourceContainer.java#L86

like image 43
John Ament Avatar answered Nov 15 '22 05:11

John Ament