目标org.codehaus.mojo:exec-maven-plugin:1.6.0:java的参数'mainClass'丢失或无效

时间:2019-03-25 22:31:13

标签: java maven pom.xml

我想在pom.xml中设置主类来运行exec:java,我检查了很多资源,但仍然遇到相同的错误。

我尝试将其放在执行标签下。

[0] => Array
    (
        [lineupSet] => Array
            (
                [0] => Array
                    (
                        [0] => Array
                            (
                                [formula] => Array
                                    (
                                        [totalPoints] => 220.66
                                    )

                                [name] => test1
                            )

                        [1] => Array
                            (
                                [formula] => Array
                                    (
                                        [totalPoints] => 214.76
                                    )

                                [name] => test2
                            )

                    )

            )

    )

我的主类位于应用程序目录下。

TicTacToe / TicTacToe-Game / src / main / java / com / mertilovski / app

pom.xml在TicTacToe目录中。 那是我跑的地方

mvn exec:java -Dexec.mainClass =“ com.mertilovski.app.Game”

我尝试制作com.mertilovski.app软件包;声明放在顶部。

mvn exec:java -Dexec.mainClass =“ src.main.java.com.mertilovski.app.com.mertilovski.app.Game “

结果是:

<build>
    <plugins>
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>com.mertilovski.app.Game</mainClass> 
                </configuration>
            </execution>
        </executions>

        </plugin>
    </plugins>
</build>

http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

2 个答案:

答案 0 :(得分:1)

您的 XML 结构似乎不正确,因为 configuration 节点应该在 executions (docs) 之外:

        <executions>
            <execution>
                <goals>
                    <goal>java</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>com.mertilovski.app.Game</mainClass> 
        </configuration>

答案 1 :(得分:0)

首先,我在Game.java文件的顶部声明了com.mertilovski.app软件包。 比我跑

 mvn exec:java -Dexec.mainClass="com.mertilovski.app.Game"

pom.xml看起来像这样(其余部分相同)

                <configuration>
                    <mainClass>com.mertilovski.app.Game</mainClass> 
                </configuration>

当我运行find时。类型f-名称“ Game.class”我得到:

./src/main/java/com/mertilovski/app/com/mertilovski/app/Game.class
./target/classes/com/mertilovski/app/Game.class
相关问题