如何从maven命令行执行java类文件 [英] How to execute a java class file from maven command line
问题描述
我正在尝试从maven命令行运行一个类但是出现以下错误。不知道我错过了什么。有人可以指导吗?
I am trying to run a class from the maven command line but getting following error. Not sure what am I missing. Can anybody please guide?
命令
C:\my-samples\MavenCommandLine>mvn exec:java -Dexec:mainClass=com.study.maven.Main
错误日志
[错误]无法执行目标org.codehaus.mojo:exec-maven-插件:1.3.2:项目MavenCommandLine上的java(default-cli):目标org.codehaus.mojo的参数'mainClass':exec-maven-plugin:1.3.2:java缺失或无效 - > [帮助1]
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project MavenCommandLine: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java are missing or invalid -> [Help 1]
Main.java
package com.study.maven;
public class Main {
public static void main(String[] args) {
System.out.println("Hello Maven!");
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.study</groupId>
<artifactId>MavenCommandLine</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</project>
推荐答案
它是 -Dexec.mainClass
而不是 -Dexec:mainClass
(点而不是冒号)。
It's -Dexec.mainClass
instead of -Dexec:mainClass
(dot instead of a colon).
参见使用情况页面。
这篇关于如何从maven命令行执行java类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!