3

Is there a way to read a text from a text.file and set it to maven property in pom.xml maven? I am trying with the below code. But, I will need to read the text from tmp.txt and assign it to the maven property "token".

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.5.0</version>
    <executions>
    <execution>
    <id>generate-random-string</id>
    <phase>install</phase>
    <goals>
    <goal>exec</goal>
    </goals>
    <configuration>
    <executable>bash</executable>
    <arguments>
    <argument>temp.sh</argument>
    </arguments>
    <workingDirectory>temp.txt</workingDirectory>
    </configuration>
    </execution>
    </executions>
</plugin>

temp.sh

PWD=${openssl rand hex 12}
echo $PWD >> temp.txt

1 Answers1

-1

You can use the properties-maven-plugin: https://www.mojohaus.org/properties-maven-plugin/

In your pom.xml. Put the file path of the generated file on the configuration section.

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0.0</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <!-- your generated file -->
                <file>temp.txt</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
jordiburgos
  • 5,964
  • 4
  • 46
  • 80