将文件读入Maven属性 [英] Read a file into a Maven property

查看:83
本文介绍了将文件读入Maven属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以读取文件并将全部内容存储到Maven属性中?

Is it possible to read a file and store the entire contents into a Maven property?

我正在尝试生成一些自定义JavaDoc,并且它们具有设置标头的选项,但是它必须是字符串,而不是文件名(出于某种原因).显然,我不想将一堆HTML放入pom.xml中,因此我需要一种将header.html读取为Maven属性的方法.

I'm trying to generate some custom JavaDocs, and they have an option to set a header, but it has to be a string, not a file name (for some reason). I obviously don't want to put a bunch of HTML into my pom.xml, so I need a way to read my header.html as a Maven property.

这可能吗?我找不到标准方法,但似乎Maven插件可能会做到这一点.

Is this possible? I'm not able to find a standard way, but it seems like a Maven plugin might do this.

显然蚂蚁有我想要的东西,但我更喜欢轻一点的东西比Ant任务重.

Apparently Ant has what I want, but I'd prefer something lighter weight than the Ant task.

推荐答案

请参见 properties-maven-plugin .

如果您不想使用 .properties 文件,那么我建议您使用Groovy插件和一个我编写的小脚本:

If you'd like not to use .properties file, than I can suggest to use the Groovy plugin and a small script that I've written:

<plugin>
  <groupId>org.codehaus.gmaven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.4</version>
  <executions>
    <execution>
      <phase>generate-resources</phase>
      <goals>
        <goal>execute</goal>
      </goals>
      <configuration>
        <properties>
          <header_file>header.html</header_file>
        </properties>
        <source>
          def file = new File(project.properties.header_file)
          project.properties.header_content = file.getText()
        </source>
      </configuration>
    </execution>
  </executions>
</plugin>

执行此插件后,您应该能够引用包含header.html文件内容的${header_content}属性.

After execution of this plugin, you should be able to refer to ${header_content} property that contains header.html file contents.

这篇关于将文件读入Maven属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆