gpt4 book ai didi

java - 测试阶段之前的 Maven 运行类 : exec-maven-plugin exec:java not executing class

转载 作者:搜寻专家 更新时间:2023-11-01 04:04:17 24 4
gpt4 key购买 nike

我正在 Jenkins 盒子上运行使用 Maven 构建的 jUnit4 测试。我的目标是在执行测试之前恢复测试数据库。

看起来 exec-maven-plugin 是可行的方法,但我无法让它运行。任何指针?虽然有很多示例,但 mojo 网站上的文档非常薄。

我需要上的课目前位于:

MyProject.src.test.java._tools.BuildTestEnvironment.java

我的 pom.xml 包括:

<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>build-test-environment</id>
<phase>generate-test-resources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>src.test.java._tools.BuildTestEnvironment</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>

在 Jenkins 中运行这个,什么也没有发生。如果我在本地运行它,我会得到

我尝试过但没有成功的事情:

  1. 在 Jenkins 中运行构建:什么都没发生。项目构建并开始运行测试,但我的类没有运行。

  2. 在本地运行构建:与在 Jenkins 中的结果相同。不足为奇。

  3. 在本地运行生成测试资源:ClassNotFoundException。即:

    mvn exec:java generate-test-resources
    java.lang.ClassNotFoundException: src.test.java._tools.BuildTestEnvironment

  4. 将类编译成一个 jar,并将其添加到我的 pom。

更新:

阅读@ppuskar 的评论后,我尝试稍微移动一下我的 buildxxx 类。将其移动到 src.main.java._tools.BuildTestEnvironment 后,我​​仍然收到类似的消息。这是我的构建日志,以防有帮助:

[DEBUG] Invoking : test.java._tools.BuildTestEnvironment.main()
[DEBUG] Plugin Dependencies will be excluded.
[DEBUG] Project Dependencies will be included.
[DEBUG] Collected project artifacts [joda-time:joda-time:jar:2.3:compile, net.sf.jt400:jt400:jar:6.7:compile, junit:junit:jar:4.11:compile, org.hamcrest:hamcrest-core:jar:1.3:compile, com.fasterxml.jackson.core:jackson-core:jar:2.3.0:compile, com.fasterxml.jackson.core:jackson-databind:jar:2.3.0:compile, com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile, org.hamcrest:hamcrest-all:jar:1.3:compile, org.apache.logging.log4j:log4j-api:jar:2.0-rc1:compile, org.apache.logging.log4j:log4j-core:jar:2.0-rc1:compile]
[DEBUG] Collected project classpath [C:\workspace\VSP_UnitTest\target\classes]
[DEBUG] Adding to classpath : file:/C:/workspace/VSP_UnitTest/target/classes/
[DEBUG] Adding project dependency artifact: joda-time to classpath
[DEBUG] Adding project dependency artifact: jt400 to classpath
[DEBUG] Adding project dependency artifact: junit to classpath
[DEBUG] Adding project dependency artifact: hamcrest-core to classpath
[DEBUG] Adding project dependency artifact: jackson-core to classpath
[DEBUG] Adding project dependency artifact: jackson-databind to classpath
[DEBUG] Adding project dependency artifact: jackson-annotations to classpath
[DEBUG] Adding project dependency artifact: hamcrest-all to classpath
[DEBUG] Adding project dependency artifact: log4j-api to classpath
[DEBUG] Adding project dependency artifact: log4j-core to classpath
[DEBUG] joining on thread Thread[test.java._tools.BuildTestEnvironment.main(),5,test.java._tools.BuildTestEnvironment]
[WARNING] java.lang.ClassNotFoundException: test.java._tools.BuildTestEnvironment
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
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:281)
at java.lang.Thread.run(Thread.java:724)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.602 s
[INFO] Finished at: 2014-05-15T14:38:50-05:00
[INFO] Final Memory: 12M/152M
[INFO] ------------------------------------------------------------------------

最佳答案

我想将此作为评论留下来回应 Rebzie 的评论,但我没有声誉。

But then you have test configuration in your main configuration

Exec Maven 插件支持更改类路径范围,这样您就可以使用测试范围内的资源,而无需将它们移出测试包,如下所示:

<configuration>
<mainClass>src.test.java._tools.BuildTestEnvironment</mainClass>
<classpathScope>test</classpathScope>
</configuration>

这提供了一个干净的解决方案,您的测试设置代码保留在您的测试资源中。

关于java - 测试阶段之前的 Maven 运行类 : exec-maven-plugin exec:java not executing class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23659829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com