我有一个使用MojoHaus的项目
Exec Maven plugin
运行一些Java代码。这是
pom.xml
文件:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.happycoding</groupId>
<artifactId>google-cloud-vision-hello-world-standalone</artifactId>
<version>1</version>
<properties>
<mainClass>io.happycoding.vision.CloudVisionHelloWorld</mainClass>
<exec.cleanupDaemonThreads>false</exec.cleanupDaemonThreads>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>1.100.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
这工作得很好,我可以使用以下命令运行我的代码:
mvn clean package exec:java
我明白
exec-maven-plugin
插件,在
plugins
标签,使用
mainClass
财产。
我惊讶地发现这
pom.xml
也起作用:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.happycoding</groupId>
<artifactId>google-cloud-vision-hello-world-standalone</artifactId>
<version>1</version>
<properties>
<exec.mainClass>io.happycoding.vision.CloudVisionHelloWorld</exec.mainClass>
<exec.cleanupDaemonThreads>false</exec.cleanupDaemonThreads>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>1.100.0</version>
</dependency>
</dependencies>
</project>
此文件指定
exec.mainClass
属性,但未指定任何插件。但是,我仍然可以用这个命令很好地运行我的代码:
mvn干净包exec:java
但我不明白Maven如何知道在没有指定任何插件的情况下运行此命令。
默认情况下,Exec Maven插件是否以某种方式自动安装在Maven中?或者是
exec.mainClass
以某种方式设置Maven中不同默认工具使用的属性?
我试着读
official documentation
,但我没有看到任何提到默认情况下是否包含该插件的内容。
我已经
found
我也可以通过
exec.mainClass
属性作为命令行参数输入,但我仍然不明白Maven在没有明确定义插件的情况下如何处理它。
我更喜欢较短的文件,但我想确保我了解它是如何工作的,并且我不会错过任何以后会咬我的东西。