【问题标题】:Maven store MD5 checksum of file and file size in properties then filter another fileMaven 将文件和文件大小的 MD5 校验和存储在属性中,然后过滤另一个文件
【发布时间】:2016-03-23 09:51:01
【问题描述】:

我想知道 Maven 中是否有办法计算文件的 MD5 校验和和大小,将它们放入属性中,然后使用这些属性过滤(文本替换)另一个文件中的参数。我正在尝试在运行 Advanced Installer 之前为其生成一个配置文件。

【问题讨论】:

    标签: maven properties maven-plugin advanced-installer


    【解决方案1】:

    在谷歌上搜索了使用 Maven 的方法后,我决定研究使用 antrun 插件。我搜索了这两个功能,两者的第一个链接都解决了这个问题。似乎 antrun 是在 Maven 中编写大部分内容的好方法。

    我的antrun配置:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <configuration>
            <exportAntProperties>true</exportAntProperties>
        </configuration>
        <executions>
            <execution>
                <phase>initialize</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <target>
                        <property name="my_path" value="some path"/>
                        <length file="${my_path}" property="file.size"/>
                        <checksum file="${my_path}" property="file.md5"/>
                    </target>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    Maven 资源插件配置:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.7</version>
        <configuration>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>file1</include>
                        <include>file2</include>
                    </includes>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </configuration>
        <executions>
            <execution>
                <phase>compile</phase>
                <goals>
                    <goal>resources</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    这在命令行中效果很好,但由于某种原因,这些属性在 Intellij 中没有解析。 I've posted another question for that.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 2016-02-23
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2014-06-21
      • 2012-05-18
      相关资源
      最近更新 更多