简体   繁体   中英

How to execute a java class file from maven command line

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?

Command

C:\my-samples\MavenCommandLine>mvn exec:java -Dexec:mainClass=com.study.maven.Main

Error-Log

[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>

It's -Dexec.mainClass instead of -Dexec:mainClass (dot instead of a colon).

See the usage page .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM