javamavenmojo

how share a .properties file from parent project to child projects


I have a parent project with a .properties file, this file is filtering according to profiles defined over the project, this project has child projects or modules, I would like the .properties file filtered was available to use for the child projects and I can access properties of file using resourceBoundle in java or whatever.

Im tried to use, no luck How to share a filter file among Maven2 modules? -> MojoHaus Project

parent pom

<?xml version="1.0" encoding="UTF-8"?>
<project 
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.data</groupId>
    <artifactId>data2</artifactId>
    <version>data-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>dataNameapp</name>

    <modules>
        <module>child  1</module>
        <module>child  2</module>
        </modules>
.....
</project>

child project

reference parent properties in pom some code In guess

using over java code
child1/test.java

ResourceBundle resourceBundleProperties= ResourceBundle.getBundle("parentproperties")

Update

In mi parent project this file in extras is filtered and when I pass it i would like it update other inner file properties

parent--extras/filtered.properties (file filtered)
   child
   --filters/filtered.properties (get from parent)  
   --resources/final.properties  (filtered of filtered.properties)

Solution

  • You can try Maven's resources plugin to copy the file from parent project, like:

        <project>
          ...
          <build>
            <plugins>
              <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                  <execution>
                    <id>copy-resources</id>
                    <phase>process-resourcesphase>
                    <goals>
                      <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                      <outputDirectory>${basedir}/target/resources</outputDirectory>
                      <resources>          
                        <resource>
                          <directory>${project.parent.basedir}/src/resources/extras</directory>
                          <filtering>true</filtering>
                        </resource>
                      </resources>              
                    </configuration>            
                  </execution>
                </executions>
              </plugin>
            </plugins>
            ...
          </build>
          ...
        </project>