用Ant或Maven执行我的Groovy脚本 [英] Execute my groovy script with ant or maven

查看:163
本文介绍了用Ant或Maven执行我的Groovy脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容:


  • 1 Java类

  • 1 bat文件(启动Groovy脚本)

  • 1常规文件

都在同一个文件夹中。

现在我想使用Maven或Ant来运行常规文件,但我无法得到它的工作。有没有谁可以告诉我怎么写这个的pom.xml或build.xml中?我不想用bat文件了。


解决方案

与Maven,使用gmaven插件。从其文档


  

Execute本地Groovy脚本

 <&插件GT;
    <的groupId方式>组织codehaus.gmaven< /的groupId>
    <&的artifactId GT; gmaven-插件< / artifactId的>
    <&版GT; 1.3< /版本>
    <&执行GT;
        <执行与GT;
            <阶段>产生资源和LT; /阶段>
            <目标>
                <&目标GT;执行< /目标>
            < /目标>
            <结构>
                &lt;信源&GT; $ {} pom.basedir /src/main/script/myscript.groovy</source>
            &LT; /结构&gt;
        &LT; /执行&GT;
    &LT; /处决&GT;
&LT; /插件&GT;


和触发指定阶段。

或者,如果你不想给插件绑定到一个特定的阶段,你可以这样配置:

 &LT;&插件GT;
    &LT;的groupId方式&gt;组织codehaus.gmaven&LT; /的groupId&GT;
    &LT;&的artifactId GT; gmaven-插件&LT; / artifactId的&GT;
    &LT;&版GT; 1.3&LT; /版本&GT;
    &LT;结构&gt;
        &lt;信源&GT;
           的println嗨
        &LT; /源&GT;
    &LT; /结构&gt;
&LT; /插件&GT;

和电话

  MVN常规:执行

I have the following:

  • 1 java class
  • 1 bat file (starts the groovy script)
  • 1 groovy file

All in the same folder.

Now I want to use Maven or Ant to run the groovy file but I can't get it to work. Is there someone who can show me how to write this pom.xml or build.xml? I don't want to use the bat file anymore.

解决方案

With Maven, use the gmaven plugin. From its documentation:

Execute a Local Groovy Script

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>${pom.basedir}/src/main/script/myscript.groovy</source>
            </configuration>
        </execution>
    </executions>
</plugin>

And trigger the specified phase.

Or, if you don't want to bind the plugin to a particular phase, you could configure it like this:

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <configuration>
        <source>
           println "Hi"
        </source>
    </configuration>
</plugin>

And call

mvn groovy:execute

这篇关于用Ant或Maven执行我的Groovy脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆