如何使用Maven执行程序?

编程入门 行业动态 更新时间:2024-10-26 17:27:54
本文介绍了如何使用Maven执行程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想让Maven目标触发Java类的执行.我正在尝试通过Makefile行进行迁移:

I would like to have a Maven goal trigger the execution of a java class. I'm trying to migrate over a Makefile with the lines:

neotest: mvn exec:java -Dexec.mainClass="org.dhappy.test.NeoTraverse"

我希望mvn neotest产生make neotest当前所做的事情.

And I would like mvn neotest to produce what make neotest does currently.

exec插件文档和 Maven Ant任务页面具有任何简单的示例.

Neither the exec plugin documentation nor the Maven Ant tasks pages had any sort of straightforward example.

当前,我在:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1</version> <executions><execution> <goals><goal>java</goal></goals> </execution></executions> <configuration> <mainClass>org.dhappy.test.NeoTraverse</mainClass> </configuration> </plugin>

不过,我不知道如何从命令行触发插件.

I don't know how to trigger the plugin from the command line, though.

推荐答案

使用您为exec-maven-plugin定义的全局配置:

With the global configuration that you have defined for the exec-maven-plugin:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.4.0</version> <configuration> <mainClass>org.dhappy.test.NeoTraverse</mainClass> </configuration> </plugin>

在命令行上调用mvn exec:java将会调用配置为执行类org.dhappy.test.NeoTraverse的插件.

invoking mvn exec:java on the command line will invoke the plugin which is configured to execute the class org.dhappy.test.NeoTraverse.

因此,要从命令行触发插件,只需运行:

So, to trigger the plugin from the command line, just run:

mvn exec:java

现在,如果要在标准构建中执行exec:java目标,则需要将该目标绑定到默认生命周期.为此,请在execution元素中声明要将目标绑定到的phase:

Now, if you want to execute the exec:java goal as part of your standard build, you'll need to bind the goal to a particular phase of the default lifecycle. To do this, declare the phase to which you want to bind the goal in the execution element:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.4</version> <executions> <execution> <id>my-execution</id> <phase>package</phase> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>org.dhappy.test.NeoTraverse</mainClass> </configuration> </plugin>

在此示例中,您的类将在package阶段执行.这只是一个示例,请对其进行调整以适合您的需求.在插件版本1.1中也可以使用.

With this example, your class would be executed during the package phase. This is just an example, adapt it to suit your needs. Works also with plugin version 1.1.

更多推荐

如何使用Maven执行程序?

本文发布于:2023-11-23 09:53:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621014.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   程序   Maven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!