Maven project not 运行, main class invalid or missing 错误

Maven project not running, main class invalid or missing error

我将一个 java 项目转换为 Maven 项目,它构建和清理都很好,但是当我尝试使用 mvn exec:java 运行 它时,我收到以下错误:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli) on project ExcelPublicationService: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java are missing or invalid -> [Help 1]

我的 pom 文件:

<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>ExcelPublicationService</groupId>
<artifactId>ExcelPublicationService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <mainClass>bns.gwt.dpm.service.rest.main.DynamicUdfPublicationServer</mainClass>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

</build>
<dependencies>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>2.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.grizzly</groupId>
        <artifactId>grizzly-http-server</artifactId>
        <version>2.3.8</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>2.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-grizzly2-http</artifactId>
        <version>2.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-sse</artifactId>
        <version>2.5.1</version>
    </dependency>

</dependencies>

主要 class 位于: src\main\java\bns\gwt\dpm\service\rest\main

它叫做 DynamicUdfPublicationServer.java

并且有一个包名:

package bns.gwt.dpm.service.rest.main

源文件位于:

ExcelPublicationService/src/main/java

并且 Maven 将 classes 编译为:

ExcelPublicationService\target\classes

你必须使用exec-maven-plugin for exec:java goal . See the plugin usage here

<build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <mainClass>bns.gwt.dpm.service.rest.main.DynamicUdfPublicationServer</mainClass>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads>
                </configuration>
            </plugin>
        </plugins>
</build>

请注意,您不需要 <pluginManagement>... <pluginManagement/> 个标签。

从命令行,你必须执行

mvn exec:java -Dexec.mainClass="bns.gwt.dpm.service.rest.main.DynamicUdfPublicationServer"