我正在使用此处包含的代码来确定给定值是否为有效日期.在一个特定情况下,它正在评估以下街道地址:
100 112TH AVE NE
显然不是约会,但Java将其解释为:
太阳1月12日00:00:00 EST 100
有问题的代码:
String DATE_FORMAT = "yyyyMMdd";
try {
DateFormat dfyyyyMMdd = new SimpleDateFormat(DATE_FORMAT);
dfyyyyMMdd.setLenient(false);
Date formattedDate;
formattedDate = dfyyyyMMdd.parse(aValue);
console.debug(String.format("%s = %s","formattedDate",formattedDate));
} catch (ParseException e) {
// Not a date
}
Run Code Online (Sandbox Code Playgroud)
控制台返回:
11:41:40.063 DEBUG TestValues | formattedDate = Sun 1月12日00:00:00 EST 100
知道这里发生了什么吗?
我在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>
Run Code Online (Sandbox Code Playgroud)
在Jenkins运行,没有任何事情发生.如果我在本地运行它,我会
我尝试过的事情没有成功:
在Jenkins中运行构建:没有任何事情发生.该项目构建并开始运行测试,但我的课程没有运行.
在本地运行构建:与Jenkins中的结果相同.这并不奇怪.
在本地运行generate-test-resources:ClassNotFoundException.即:
mvn exec:java generate-test-resources
java.lang.ClassNotFoundException:src.test.java._tools.BuildTestEnvironment
将类编译成jar,然后将其添加到我的pom中.
更新:
在阅读@ ppuskar的评论之后,我尝试了一下我的buildxxx类.将它移动到src.main.java._tools.BuildTestEnvironment后,我仍然收到类似的消息.这是我的构建日志,如果有帮助:
[DEBUG]调用:test.java._tools.BuildTestEnvironment.main()
[DEBUG]插件依赖项将被排除.
[DEBUG]将包括项目依赖项.
[DEBUG]收集的项目工件[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]收集项目类路径[C:\ workspace\VSP_UnitTest\target\classes]
[DEBUG]添加到classpath:file:/C:/ workspace/VSP_UnitTest/target/classes/
[DEBUG]添加项目依赖项工件:joda-time到classpath
[DEBUG]添加项目依赖项工件:jt400到classpath
[DEBUG]添加项目依赖项工件:junit到classpath
[DEBUG]添加项目依赖项工件:hamcrest-core到classpath
[DEBUG]添加项目依赖项工件:jackson -core to classpath
[DEBUG]添加项目依赖项工件:jackson-databind到classpath
[DEBUG]添加项目依赖项工件:jackson-annotations到classpath
[DEBUG]添加项目依赖项工件:hamcrest-all到classpath
[DEBUG]添加项目依赖项工件:log4j-api到classpath
[DEBUG]添加项目依赖项工件:log4j-core到类路径
[DEBUG]加入线程Thread [test.java._tools.BuildTestEnvironment.main(),5,test.java._tools.BuildTestEnvironment]
[警告] java.lang.ClassNotFoundException:
java.net.URLClassLoader $ 1.run中的test.java._tools.BuildTestEnvironment(URLClassLoader.java:366)
java.net.URLClassLoader $ …
后续问题的后续: Maven在测试阶段之前运行类:exec-maven-plugin exec:java不执行类.
我在jenkins盒子上运行jUnit4测试,用maven构建.我需要在构建的测试阶段之前运行特定的main方法java程序.目的是在测试运行之前恢复测试数据库.
如果我运行了这个exec分配给的确切阶段,我的类按预期执行; 但是当我运行整个构建时,我的类不会执行:
具体来说,它运行:
mvn -X exec:java generate-test-resources
但不运行:
mvn -X -e install
- 或 -
mvn -X -e clean install
pom.xml: 我的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>main.java._tools.BuildTestEnvironment</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Run Code Online (Sandbox Code Playgroud)
生命周期默认: 我还没有看到maven的生命周期.日志将其报告为:
[DEBUG] Lifecycle default -> [
validate,
initialize,
generate-sources,
process-sources,
generate-resources,
process-resources,
compile,
process-classes,
generate-test-sources,
process-test-sources,
generate-test-resources,
process-test-resources,
test-compile,
process-test-classes,
test,
prepare-package,
package, …
Run Code Online (Sandbox Code Playgroud)