繁体   English   中英

有没有办法从text.file中读取文本并将其设置为pom.xml maven中的maven属性?

[英]Is there a way to read a text from a text.file and set it to maven property in pom.xml maven?

有没有办法从text.file中读取文本并将其设置为pom.xml maven中的maven属性? 我正在尝试以下代码。 但是,我需要从tmp.txt中读取文本并将其分配给Maven属性“ 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>

临时文件

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

您可以使用properties-maven-plugin: https : //www.mojohaus.org/properties-maven-plugin/

在您的pom.xml中。 将生成的文件的文件路径放在配置部分。

  <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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM