ReporNG报告构建到Jenkins上显示乱码问题

问题描述:

ReportNG在本地上的报告编码格式都正常,但构建到Jenkins上却显示乱码,如下图

image.png

问题解决:

网上百度了解决方法是修改源码包。

  1. 下载ReportNG源码包:https://github.com/dwdyer/reportng

  2. 解压缩后 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();
        }
    }
  1. 修改完后打包
  • 修改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
  1. 把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>
  1. 运行后却报以下错误


    reportng错误1.jpg

解决方法:导入velocity包

        <dependency>
            <groupId>velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.4</version>
        </dependency>
  1. 提交到Jenkins运行,问题解决
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容