猿问

如何使用Maven执行程序?

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


neotest:

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

我想mvn neotest提出make neotest目前的工作。


无论是Exec插件的文件,也不是Maven的Ant任务的网页有任何形式的简单例子。


目前,我在:


<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>

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


慕后森
浏览 548回答 2
2回答

慕田峪9158850

为了执行多个程序,我还需要一个profiles部分:<profiles>&nbsp; <profile>&nbsp; &nbsp; <id>traverse</id>&nbsp; &nbsp; <activation>&nbsp; &nbsp; &nbsp; <property>&nbsp; &nbsp; &nbsp; &nbsp; <name>traverse</name>&nbsp; &nbsp; &nbsp; </property>&nbsp; &nbsp; </activation>&nbsp; &nbsp; <build>&nbsp; &nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.codehaus.mojo</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>exec-maven-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <executable>java</executable>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <arguments>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <argument>-classpath</argument>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <argument>org.dhappy.test.NeoTraverse</argument>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </arguments>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; </plugins>&nbsp; &nbsp; </build>&nbsp; </profile></profiles>然后可以执行以下命令:mvn exec:exec -Dtraverse
随时随地看视频慕课网APP
我要回答