Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven resource filtering of json file

Tags:

java

json

maven

In my current project I have a submodule which is using the maven exec plugin to run a test service which pulls configuration files from a location outside of the resources/testResources folders.

I need to use filtering to inject an environment variable into a few of the configuration files. This is working for one of the files, a .properties file, but not for another file which is a .json. In the latter case it simply leaves the variable in the json file. The two files are right next to each other in the filtered directory.

Here is the filtering snippet from the submodule:

<build>
  <finalName>${artifactId}</finalName>
  <testResources>
    <testResource>
      <filtering>true</filtering>
      <directory>../etc</directory>
    </testResource>
  </testResources>

json file:

{ "customMappings" :
    { "tag:example.com:/vagrant/" : "file:${VAGRANT_CWD}" }
}

Abbreviated project structure:

  • project
    • etc
      • config.properties
      • config.json
    • submodule
      • pom.xml

The submodule is definitely loading both files, but only filtering the .properties file.

Is there something special about it being a json file that would prevent filtering from happening to it? Anything that can be done about this?

like image 305
Ben Pennell Avatar asked Oct 19 '22 04:10

Ben Pennell


1 Answers

For what its worth, I did eventually get this to work. I found that I had to directly list the file for inclusion in order to get it to be processed (its been a long time so hopefully this is the correct solution):

<build>
  <finalName>${artifactId}</finalName>
  <testResources>
    <testResource>
      <filtering>true</filtering>
      <directory>../etc</directory>
      <includes>
        <include>config.json</include>
        <include>config.properties</include>
      </includes>
    </testResource>
  </testResources>
...
like image 68
Ben Pennell Avatar answered Oct 21 '22 05:10

Ben Pennell