Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read a file into a Maven property

Tags:

maven

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.

like image 547
Brendan Long Avatar asked Feb 17 '12 20:02

Brendan Long


1 Answers

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.

like image 139
Andrew Logvinov Avatar answered Oct 13 '22 19:10

Andrew Logvinov