Maven 2 如何使用Maven执行程序?
我希望有一个Maven目标触发java类的执行。我正在尝试通过Maven 2 如何使用Maven执行程序?,maven-2,maven-plugin,Maven 2,Maven Plugin,我希望有一个Maven目标触发java类的执行。我正在尝试通过Makefile进行迁移,其中包含以下行: neotest: mvn exec:java -Dexec.mainClass="org.dhappy.test.NeoTraverse" 我想mvn-neotest来制作make-neotest目前的功能 这两个页面都没有任何简单的例子 目前,我在: <plugin> <groupId>org.codehaus.mojo</groupId>
Makefile
进行迁移,其中包含以下行:
neotest:
mvn exec:java -Dexec.mainClass="org.dhappy.test.NeoTraverse"
我想mvn-neotest
来制作make-neotest
目前的功能
这两个页面都没有任何简单的例子
目前,我在:
<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>
org.codehaus.mojo
execmaven插件
1.1
JAVA
org.dhappy.test.NeoTraverse
但是,我不知道如何从命令行触发插件。使用您为exec maven插件定义的全局配置:
<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>
现在,如果您想在标准构建中执行exec:java
目标,则需要将该目标绑定到构建的特定阶段。为此,在执行
元素中声明要将目标绑定到的阶段
:
<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>
org.codehaus.mojo
execmaven插件
1.4
我的死刑
包裹
JAVA
org.dhappy.test.NeoTraverse
在本例中,您的类将在
package
阶段执行。这只是一个例子,调整它以适应您的需要。也适用于插件版本1.1。为了执行多个程序,我还需要一个profiles
部分:
<profiles>
<profile>
<id>traverse</id>
<activation>
<property>
<name>traverse</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<argument>org.dhappy.test.NeoTraverse</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
那条
-classpath
行是怎么回事?我不认为这是正确的。是的,很可能是
标签错误地到达了那里,应该被删除。所以这一行看起来只是:-classpath
,这不是一个错误。这表明pom.xml中指定的依赖项应该用作类路径的一部分。起初我感到困惑:exec:java
也可以用于Scala和Clojure代码,它本身不一定是java代码。版本应该是1.4.0
<profiles>
<profile>
<id>traverse</id>
<activation>
<property>
<name>traverse</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<argument>org.dhappy.test.NeoTraverse</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
mvn exec:exec -Ptraverse