8

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

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.

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

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

Brendan Long
  • 53,280
  • 21
  • 146
  • 188

1 Answers1

14

See this question on SO. And here is the properties-maven-plugin.

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>

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

Ales
  • 5
  • 3
Andrew Logvinov
  • 21,181
  • 6
  • 52
  • 54