博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
maven插件打包exec_Exec Maven插件–从Maven Build运行Java程序
阅读量:2533 次
发布时间:2019-05-11

本文共 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插件有两个目标:

  1. exec:exec – can be used to execute any program in a separate process.

    exec:exec –可用于在单独的进程中执行任何程序。
  2. exec:java – can be used to run a Java program in the same VM.

    exec:java –可用于在同一VM中运行Java程序。

In this tutorial, we will learn how to use exec:java to run a Java program from our maven project.

在本教程中,我们将从maven项目中学习如何使用exec:java运行Java程序。

步骤1:将exec-maven-plugin配置添加到pom.xml (Step 1: Adding exec-maven-plugin Configurations to pom.xml)

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********");	}}

步骤2:使用exec:java目标运行Maven构建 (Step 2: Running the maven build with exec:java goal)

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] ------------------------------------------------------------------------$
Exec Maven Plugin Java Example
Exec Maven Plugin Java Example
Exec Maven插件Java示例

参考文献: (References:)

翻译自:

maven插件打包exec

转载地址:http://tqlzd.baihongyu.com/

你可能感兴趣的文章
案例:手动输入一个字符串,打散放进一个列表,小写字母反序 大写字母保持不变...
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>
阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
查看>>
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>
设计原理+设计模式
查看>>
音视频处理
查看>>
tomcat 7服务器跨域问题解决
查看>>
前台实现ajax 需注意的地方
查看>>
Jenkins安装配置
查看>>
个人工作总结05(第二阶段)
查看>>
Java clone() 浅拷贝 深拷贝
查看>>
深入理解Java虚拟机&运行时数据区
查看>>
02-环境搭建
查看>>
spring第二冲刺阶段第七天
查看>>
搜索框键盘抬起事件2
查看>>
阿里百川SDK初始化失败 错误码是203
查看>>
透析Java本质-谁创建了对象,this是什么
查看>>