我想让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执行程序?
发布评论