Question

I have another maven structural problem... =/

a sample project with 3 different modules:

CONFIG (contains all configurations files)

DAO (depends on CONFIG)

SERVICE (depends on DAO and CONFIG)

The CONFIG module generates filtered resources in it's "target" folder by using the "maven-resources-plugin". How can the DAO and SERVICE modules access those filtered resources?

help help plz help =)

here's the resource filter part of the CONFIG modules POM:

<build>
    <filters>
        <filter>src/main/resources/basic.properties</filter>
    </filters>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <includes>
                                    <include>**/context*.xml</include>
                                </includes>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Was it helpful?

Solution

The CONFIG module should be producing a JAR with the filtered resources in its root. The other modules should be able to access those resources via their classpaths, which should contain the CONFIG jar, using ClassLoader.getResource(String) or ClassLoader.getResourceAsStream(String).

EDIT: after comment below.

You don't need to re-declare the Resources plugin, you simple specify the resources in the build section of the pom like this:

<build>

  <resources>
    <resource>
      <filtering>true</filtering>
      <directory>src/main/resources</directory>
      <includes>
        <include>**/context*.xml</include>
      </includes>
    </resource>
  </resources>

</build>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top