当前位置: 首页 > 知识库问答 >
问题:

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

呼延运恒
2023-03-14

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

我试着把它放在执行标签下。

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

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

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.Mertilovsti.app-Game”

结果是:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------ 
------------
[INFO] Building TicTacToe-Game 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------ 
------------
[INFO] 
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) > validate @ 
TicTacToe-Game >>>
[INFO] 
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) < validate @ 
TicTacToe-Game <<<
[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ TicTacToe- 
Game ---
[WARNING] 
java.lang.ClassNotFoundException: com.mertilovski.app.Game
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:748)
[INFO] ------------------------------------------------------------ 
------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------ 
------------
[INFO] Total time: 0.639 s
[INFO] Finished at: 2019-03-26T01:30:18+03:00
[INFO] Final Memory: 8M/106M
[INFO] ------------------------------------------------------------ 
------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven- 
plugin:1.2.1:java (default-cli) on project TicTacToe-Game: An 
exception occured while executing the Java class. 
com.mertilovski.app.Game -> [Help 1]
[ERROR]   
[ERROR] To see the full stack trace of the errors, re-run Maven 
with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug 
logging.
[ERROR] 
[ERROR] For more information about the errors and possible 
solutions, please read the following articles:
[ERROR] [Help 1] 

http://CWI ki . Apache . org/confluence/display/MAVEN/MojoExecutionException

共有2个答案

孟宏才
2023-03-14

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

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

pom.xml是这样的(剩余部分相同)

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

当我运行查找时。-键入f -name "Game.class "我得到:

./src/main/java/com/mertilovski/app/com/mertilovski/app/Game.class
./target/classes/com/mertilovski/app/Game.class
姜俊逸
2023-03-14

您的XML结构似乎不正确,因为< code >配置节点应该在< code >执行(文档)之外:

        <executions>
            <execution>
                <goals>
                    <goal>java</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>com.mertilovski.app.Game</mainClass> 
        </configuration>
 类似资料: