Maven工程打包生成MD5和SHA-1校验文件

文件经过网络传输等原因对源项目包造成损坏时方便排查,一般做法是在maven工程打包时自动自动生成MD5和SHA-1校验文件。具体做法是在maven的pom文件里的build->plugins->添加 如下代码:

​
            <!-- 生成MD5校验文件 -->
            <plugin>
                <groupId>net.ju-n.maven.plugins</groupId>
                <artifactId>checksum-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <id>checksum-maven-plugin-files</id>
                        <phase>package</phase>
                        <goals>
                            <goal>files</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <fileSets>
                        <fileSet>
                            <directory>${project.build.directory}</directory>
                            <includes>
                                <include>*.jar</include>
                            </includes>
                        </fileSet>
                    </fileSets>
                    <algorithms>
                        <algorithm>SHA-1</algorithm>
                        <algorithm>MD5</algorithm>
                    </algorithms>
                </configuration>
            </plugin>

​

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
maven-replacer-plugin插件主要用于文件内容替换,不太适合用于生成文件并输入内容。但是,你可以使用maven-resources-plugin插件生成文件并将内容写入文件中。 以下是一个示例: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>generate-file</id> <phase>process-resources</phase> <goals> <goal>resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>example.txt</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 在这个例子中,我们使用maven-resources-plugin插件在process-resources阶段生成文件并将内容写入文件中。 首先,在configuration标签中设置outputDirectory为${project.build.outputDirectory},这将指定生成的文件输出到项目的target目录下。 接下来,在resources标签中,我们指定要生成的文件名为example.txt,这个文件名必须位于src/main/resources目录下。同时,我们将filtering属性设置为true,这将启用Maven的资源过滤机制,可以在文件中使用Maven的属性占位符。 然后,在执行过程中,maven-resources-plugin插件将会在target/classes目录下生成一个名为example.txt的文件,并将文件中的所有Maven属性占位符替换为实际的值。 如果你需要在生成的文件中写入特定的内容,可以在example.txt文件中使用Maven属性占位符,然后在pom.xml中使用<properties>标签定义属性值。 例如,在example.txt文件中写入如下内容: ``` Hello, ${username}! ``` 在pom.xml中定义属性值: ```xml <properties> <username>world</username> </properties> ``` 这将生成一个名为example.txt的文件,文件中的"Hello, ${username}!"将被替换为"Hello, world!"。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值