本文介绍了Maven:在构建完成时触发自定义命令,具体取决于结果(成功/失败)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在命令行上使用Maven,我的构建需要一段时间才能完成(1-2分钟).我正在寻找一种可能性,可以在构建完成时挂入构建的END并触发特定命令(通过ant等启动程序),具体取决于构建的结果(成功/失败). /p>

我的目标是我的计算机只是播放声音(一个声音用于成功构建,另一个声音用于构建失败),因此我会注意到我的构建已完成.

我能意识到吗?我想可能会有Ant,但我希望没有Ant也能做到.

解决方案

这应该可以帮助您入门.

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>groovy-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            import java.io.File;
                            import javax.sound.sampled.AudioInputStream;
                            import javax.sound.sampled.AudioSystem;
                            import javax.sound.sampled.Clip;
                            import javax.sound.sampled.DataLine;
                            File soundFile = new File("audio/beep.wav");
                            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);
                            DataLine.Info info = new DataLine.Info(Clip.class,sound.getFormat());
                            Clip clip = (Clip) AudioSystem.getLine(info);
                            clip.open(sound);
                            clip.start();
                            sleep(5000);                        
                        </source>
                    </configuration>
                </execution>
            </executions>
        </plugin>

您将需要此Maven存储库.

<repository>
    <id>org.codehaus.repository</id>
    <name>Codehaus repository</name>
    <url>http://repo1.maven.org/maven2/org/codehaus/mojo/</url>
</repository>

I'm using Maven on the command line, and my build takes a while to complete (1-2min). I'm looking for a possibility to hook into the END of the build and trigger a specific command (start a program by ant, etc.) when the build is finished - dependent to the outcome of my build (Successful/Failed).

My goal is that my computer just plays a sound (one for successful build, another for a failed build) so i'll notice that my build is done.

Can i realize that, and how?I guess Ant would be a possibility, but i hope i can also do it without Ant.

解决方案

This should get you started.

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>groovy-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            import java.io.File;
                            import javax.sound.sampled.AudioInputStream;
                            import javax.sound.sampled.AudioSystem;
                            import javax.sound.sampled.Clip;
                            import javax.sound.sampled.DataLine;
                            File soundFile = new File("audio/beep.wav");
                            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);
                            DataLine.Info info = new DataLine.Info(Clip.class,sound.getFormat());
                            Clip clip = (Clip) AudioSystem.getLine(info);
                            clip.open(sound);
                            clip.start();
                            sleep(5000);                        
                        </source>
                    </configuration>
                </execution>
            </executions>
        </plugin>

You'll want this Maven repository.

<repository>
    <id>org.codehaus.repository</id>
    <name>Codehaus repository</name>
    <url>http://repo1.maven.org/maven2/org/codehaus/mojo/</url>
</repository>

这篇关于Maven:在构建完成时触发自定义命令,具体取决于结果(成功/失败)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 15:09