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

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

我正在尝试通过 Maven 运行 配置 中的以下命令使用 pom.xml 文件执行 testNG main class。 =14=]

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

这里我用的是Java8.

但是我得到了以下错误。

[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

请帮我解决这个问题。

假设您在 src/test/java

中有一个 Main.java

将此添加到您的 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>

和 运行 它通过 :

mvn clean installmvn exec:java