maven pom的资源元素

时间:2012-07-03 09:01:44

标签: maven pom.xml

我是maven的新手,遇到了资源部分。 maven项目描述符(版本4.0)的引用声明“此元素描述与项目或单元测试关联的所有类路径资源”(link)。但是这个描述我不明白/似乎对我来说是抽象的。为什么我要描述类路径资源?它如何影响项目生命周期?

的Matthias

2 个答案:

答案 0 :(得分:4)

通常你有src / main / resources文件夹,其中包含将打包到jar中的资源。上面文件夹中的所有内容将自动打包到jar中,并可通过getResource访问...通过pom中的资源区域,您可以filter files from their way src/main/resources to the target/classes folder

<project>
  ...
  <name>My Resources Plugin Practice Project</name>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

Maven的生命周期不受此影响。

答案 1 :(得分:1)

例如,此功能允许您在.properties文件中使用Maven变量。只需在<resources>部分中声明.properties所在的目录,您就可以使用$ {project.name}或其他任何内容。

的pom.xml:

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

version.properties:

version=${pom.version}
timestamp=${timestamp}

($ {timestamp}是使用Maven Build Number插件创建的。

相关问题