无法从 pom.xml 执行 mainClass

not able to execute mainClass from pom.xml

我正在尝试执行其中提到了 mainClasspom.xml,但它没有被执行。

命令:mvn test -f "path_to_pom.xml\pom.xml"

输出:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @Project ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ Project ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Project ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Personal\selenium\Project\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @Project ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 5 source files to D:\Personal\selenium\Project\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ Project ---
[WARNING] useSystemClassloader setting has no effect when not forking
[INFO] Surefire report directory: D:\Personal\selenium\Project\target\surefire-reports
Running test.java.com.utilities.TestController
Configuring TestNG with: TestNG652Configurator
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.295 sec - in t
est.java.com.utilities.TestController

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.138 s
[INFO] Finished at: 2016-03-08T11:45:54+05:30
[INFO] Final Memory: 20M/225M
[INFO] ------------------------------------------------------------------------

我尝试从 eclipse IDE 执行它,但也没有从那里执行。

但是,在cmd的maven命令中指定-DmainClass="<className>",正在执行class。

以下是来自 pom.xml 的条目:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>test.java.com.utilities.TestController</mainClass>
    </configuration>
</plugin>

我已经执行了 mvn clean 和 Maven > Update Project,但没有帮助。

问题:我还可以做哪些其他更改来使这项工作正常进行?

您想在 test phase, hence you should add it to your plugin execution. Moreover, it seems you are running a class from the test packages which may also need test classpath 期间执行 class 以正确执行。

然后我会将以下更改应用于您发布的配置:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <phase>test</phase> <!-- ADDED -->
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>test.java.com.utilities.TestController</mainClass>
        <classpathScope>test</classpathScope> <!-- ADDED -->
    </configuration>
</plugin>

注意通过评论突出显示的 ADDED 元素。