首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从mainClass执行pom.xml

无法从mainClass执行pom.xml
EN

Stack Overflow用户
提问于 2016-03-08 06:37:14
回答 1查看 1.6K关注 0票数 1

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

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

输出:

代码语言:javascript
复制
[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中执行它,但也没有从那里执行。

但是,在cmd上的maven命令中指定-DmainClass="<className>"时,将执行类。

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

代码语言:javascript
复制
<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清理和Maven >,但这并没有帮助。

问题:我还能做什么改变来完成这个工作呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-08 08:48:57

您希望在test 相态期间执行该类,因此应该将其添加到插件execution中。此外,您似乎正在从测试包中运行一个类,该包可能还需要测试类路径才能正确执行。

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

代码语言:javascript
复制
<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元素。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35860654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档