有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java有一种从文本中读取文本的方法。文件,并将其设置为pom中的maven属性。xml专家?

有没有办法从一篇课文中读出一篇课文。文件,并将其设置为pom中的maven属性。xml专家?我正在尝试以下代码。但是,我需要阅读来自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

共 (1) 个答案

  1. # 1 楼答案

    您可以使用properties maven插件: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>