java压缩图片maven_java – 在maven构建中集成yahoo smush.it以进行图像压缩

您是否考虑过编写一个小型Maven插件来自动完成此操作?插件API非常棒,非常简单 – 您可以查看

here.基本上,您将创建一个插件项目,它接受一些XML参数并为您执行转换:

@Mojo(name = "compress", defaultPhase = "compile")

public class SmushItCompressMojo extends AbstractMojo {

@Parameter(property = "images")

String[] images;

@Parameter(property = "destination")

String destination;

@Override

public void execute() throws MojoExecutionException, MojoFailureException {

// Validate your inputs.

// For each image file:

// Compress it using a request to smush.it.

// Save the compressed image to the destination file.

// Report any errors/success.

}

}

然后,在希望使用新编写的mojo的pom.xml中,在< plugins>中使用它,如下所示. < build>下的标记:

com.stackoverflow

smush-it-maven-plugin

1.0.0-SNAPSHOT

compress

compress

${project.build.directory}/../images/1.png

${project.build.directory}/../images/2.png

${project.build.directory}/../images/3.png

${project.build.directory}/../src/main/resources/compressed/

然后,您可以将三个图像保存到压缩资源文件夹中,然后将在后续生命周期阶段打包.显然,这里有很多灵活性来确定图像来自哪里并得到保存.但是mojo本身非常简单,这正是您使用Maven自动执行特定于应用程序的任务的方式.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值