无法执行目标 org.codehaus.mojo:exec-maven-plugin:1.6.0:java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48495043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:51:56  来源:igfitidea点击:

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java

javaeclipsemavenmaven-pluginm2eclipse

提问by Mohan Kumar

I am trying to execute the testNG main class using pom.xml file by using the below command in Maven Run Configurations.

我正在尝试通过在Maven Run Configurations 中使用以下命令使用 pom.xml 文件执行 testNG 主类。

exec:java -Dexec.mainClass=com.selenium.controls.TestNGMainClass

Here, I am using Java 8.

在这里,我使用的是Java 8

But I got the below error.

但我收到以下错误。

[INFO] ------------------------------------------------------------------------
[INFO] Building seleniumScriptsRegression 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ seleniumScriptsRegression ---
[WARNING] java.lang.ClassNotFoundException: com.selenium.controls.TestNGMainClass
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.codehaus.mojo.exec.ExecJavaMojo.run(ExecJavaMojo.java:270)
at java.lang.Thread.run(Unknown Source)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.331 s
[INFO] Finished at: 2018-01-29T10:59:54+05:30
[INFO] Final Memory: 13M/32M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project seleniumScriptsRegression: An exception occured while executing the Java class. com.selenium.controls.TestNGMainClass -> [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://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Kindly help me to fix the issue.

请帮我解决这个问题。

采纳答案by user6761124

Assuming you have a Main.java in src/test/java

假设您在 src/test/java 中有一个 Main.java

Add this in your pom.xml

在你的 pom.xml 中添加这个

 <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.6.0</version>
                    <configuration>
                        <classpathScope>test</classpathScope>
                        <mainClass>Main</mainClass>
                    </configuration>
                    <executions>
                        <execution>
                            <id>run-selenium</id>
                            <phase>integration-test</phase>
                            <goals><goal>java</goal></goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

and run it via :

并通过以下方式运行它:

mvn clean installor mvn exec:java

mvn clean install或者 mvn exec:java