问题描述:
ReportNG在本地上的报告编码格式都正常,但构建到Jenkins上却显示乱码,如下图
image.png
问题解决:
网上百度了解决方法是修改源码包。
下载ReportNG源码包:https://github.com/dwdyer/reportng
解压缩后 IntelliJ IDEA打开修改AbstractReporter类:
src/java/main/org/uncommons/reportng/AbstractReporter.java
protected void generateFile(File file, String templateName, VelocityContext context) throws Exception {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
try {
Velocity.mergeTemplate(this.classpathPrefix + templateName, "UTF-8", context, writer);
writer.flush();
} finally {
writer.close();
}
}
修改为:
PS: 记住要引入包,由于源码导进来没有提示要导入包,也没有报错,会导致后面打包时一直报错。
import java.io.OutputStream;
import java.io.OutputStreamWriter;
protected void generateFile(File file,
String templateName,
VelocityContext context) throws Exception
{
// Writer writer = new BufferedWriter(new FileWriter(file));
OutputStream out=new FileOutputStream(file);
Writer writer = new BufferedWriter(new OutputStreamWriter(out,"utf-8"));
try
{
Velocity.mergeTemplate(classpathPrefix + templateName,
ENCODING,
context,
writer);
writer.flush();
}
finally
{
writer.close();
}
}
- 修改完后打包
- 修改build.xml(version版本改为1.1.5)
<property name="version" value="1.1.5"/>
<property name="artifact.identifier" value="reportng-${version}"/>
- Ant Build打包(点击RUN之后,项目生成reportng-1.1.5.jar)
PS: build.xml报红可以不用管
image.png
- 把reportng-1.1.5.jar包导入项目中
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.5</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/reportng-1.1.5.jar</systemPath>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
-
运行后却报以下错误
reportng错误1.jpg
解决方法:导入velocity包
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.4</version>
</dependency>
- 提交到Jenkins运行,问题解决