本文共 2828 字,大约阅读时间需要 9 分钟。
maven插件打包exec
Maven exec plugin allows us to execute system and Java programs from the maven command.
Maven exec插件允许我们从maven命令执行系统和Java程序。
There are two goals of the maven exec plugin:
Maven exec插件有两个目标:
In this tutorial, we will learn how to use exec:java to run a Java program from our maven project.
在本教程中,我们将从maven项目中学习如何使用exec:java运行Java程序。
If you want to use any maven plugin, you need to configure it in the pom.xml build section. Just add the below plugin configuration to your project pom.xml file.
如果要使用任何Maven插件,则需要在pom.xml构建部分中对其进行配置。 只需将以下插件配置添加到您的项目pom.xml文件即可。
org.codehaus.mojo exec-maven-plugin 1.6.0 com.journaldev.maven.utils.BuildInfo
The most important point to note here is the “mainClass” element inside the “configuration“. This is where we specify the Java class that will be executed by the exec:java goal.
这里要注意的最重要的一点就是“ 配置 “里面的“mainClass”元素。 在这里,我们指定将由exec:java目标执行的Java类。
Here is the content of the Java class. It’s a simple class where we are printing Java version details and the current time.
这是Java类的内容。 这是一个简单的类,我们在其中打印Java版本详细信息和当前时间。
package com.journaldev.maven.utils;import java.time.LocalDateTime;public class BuildInfo { public static void main(String[] args) { String javaVersion = Runtime.version().toString(); String time = LocalDateTime.now().toString(); System.out.println("********\nBuild Time: " + time + "\nJava Version: " + javaVersion + "\n********"); }}
Here is the output when we run the maven build with the exec:java goal.
这是当我们使用exec:java目标运行Maven构建时的输出。
$ mvn exec:java[INFO] Scanning for projects...[INFO] [INFO] ---------------< com.journaldev.maven:maven-example-jar >---------------[INFO] Building maven-example-jar 0.0.1-SNAPSHOT[INFO] --------------------------------[ jar ]---------------------------------[INFO] [INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ maven-example-jar ---********Build Time: 2020-01-10T12:44:17.718061Java Version: 13.0.1+9********[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 0.591 s[INFO] Finished at: 2020-01-10T12:44:17+05:30[INFO] ------------------------------------------------------------------------$
翻译自:
maven插件打包exec
转载地址:http://tqlzd.baihongyu.com/