与其他Maven模块共享过滤后的资源

时间:2014-01-07 17:08:35

标签: java maven filter resources multi-module

我有另一个maven结构问题...... = /

一个包含3个不同模块的示例项目:

CONFIG(包含所有配置文件)

DAO(取决于CONFIG)

服务(取决于DAO和CONFIG)

CONFIG模块使用“maven-resources-plugin”在其“target”文件夹中生成过滤后的资源。 DAO和SERVICE模块如何访问这些过滤后的资源?

帮助帮助plz help =)

这是CONFIG模块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>

1 个答案:

答案 0 :(得分:2)

CONFIG模块应该在其根目录中生成带有过滤资源的JAR。其他模块应该能够通过类路径访问这些资源,类路径应包含CONFIG jar,使用ClassLoader.getResource(String)ClassLoader.getResourceAsStream(String)

编辑:在下面发表评论。

您无需重新声明Resources插件,只需指定pom的resources in the build section

<build>

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

</build>
相关问题