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

标签 java maven automation yahoo image-compression

我想将 Yahoo smush.it 集成到 Maven 构建中,以在构建本身中自动执行图像压缩。

有人可以帮我做吗?

我也对其他图书馆开放。 [后端是 Java。]

最佳答案

您是否考虑过自己编写一个小型 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.
    }
}

然后,在 pom.xml希望使用您新编写的 mojo,请按以下方式在 <plugins> 中使用它在 <build> 下标记:

<plugin>
    <groupId>com.stackoverflow</groupId>
    <artifactId>smush-it-maven-plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <executions>
        <execution>
            <id>compress</id>
            <goals>
                <goal>compress</goal>
            </goal>
            <configuration>
                <images>
                    <image>${project.build.directory}/../images/1.png</image>
                    <image>${project.build.directory}/../images/2.png</image>
                    <image>${project.build.directory}/../images/3.png</image>
                </images>
                <destination>${project.build.directory}/../src/main/resources/compressed/
            </configuration>
        </execution>
    </executions>
</plugin>

然后您可以将这三个图像保存到压缩资源文件夹中,然后在生命周期的后期阶段将其打包。显然,关于图像的确切来源和保存位置,这里有很大的灵 active 。但是 mojo 本身非常简单,这正是您自动化应用程序特定任务以使用 Maven 的方式。

关于java - 在 maven 构建中集成 yahoo smush.it 以进行图像压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23778466/

相关文章:

google-apps-script - 测试自动化 Google Apps 脚本 Gmail 附加组件

java - 栈数组

java - Elasticsearch java客户端mapper_parsing_exception无法解析文档中类型[long]的字段[timeStamp]?

maven - 如何在子模块 pom 中获取 super pom basedir?

java - 将 JUnit 类别与 Maven Failsafe 插件一起使用

c# - COM 互操作、隔离和排除重复引用

java - 如果别的??尝试??我需要方法方面的帮助

java - 使用 getInt(String) 时出现 NullPointerException

java - @sun.misc.Contended 注释的值是多少?

java - 更新 Maven 在 Eclipse 中从 Java JDK 1.8 恢复到 JavaSE -1.8