---
title: 编译HiBench
description: "1. 下载HiBench源码。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengbds/testguide/tstg/kunpengbdshib_11_0007.html
sourcePath: /source/zh/kunpengbds/testguide/tstg/kunpengbdshib_11_0007.html
indexId: 836d4f3e1bccf1ac217e1812c4fb3f54a0c10cb7ac964c16231c5b767943afa463
---
# 编译HiBench

1. 下载HiBench源码。
  1 wget https://github.com/Intel-bigdata/HiBench/archive/HiBench-7.0.tar.gz

2. 解压源码包。
  1 tar -zxf HiBench-7.0.tar.gz -C ./

3. 修改“autogen/src/main/java/org/apache/hadoop/fs/dfsioe/TestDFSIO.java”文件。

  a. 进入“HiBench-HiBench-7.0”目录并打开TestDFSIO.java文件。
    1 2 cd HiBench-HiBench-7.0 vi autogen/src/main/java/org/apache/hadoop/fs/dfsioe/TestDFSIO.java

  b. 按“i”进入编辑模式，将“import org.apache.commons.logging.*;”替换为如下内容。

```
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
```


  c. 将“private static final Log LOG = FileInputFormat.LOG;”替换为如下内容。

```
private static final Logger LOG = LoggerFactory.getLogger(FileInputFormat.class);
```


  d. 按“Esc”键，输入:wq!，按“Enter”保存并退出编辑。
4. 修改“autogen/src/main/java/org/apache/hadoop/fs/dfsioe/TestDFSIOEnh.java”文件。

  a. 打开TestDFSIOEnh.java文件。
    1 vi autogen/src/main/java/org/apache/hadoop/fs/dfsioe/TestDFSIOEnh.java

  b. 按“i”进入编辑模式，在文件头部添加新的包，添加如下内容。
    1 import java.util.Arrays;

  c. 将“import org.apache.commons.logging.*;”替换为如下内容。
    1 2 import org.slf4j.Logger; import org.slf4j.LoggerFactory;

  d. 将“private static final Log LOG = LogFactory.getLog(TestDFSIOEnh.class);”替换为如下内容。
    1 private static final Logger LOG = LoggerFactory.getLogger(TestDFSIOEnh.class);

  e. 将“FileUtil.copyMerge(fs, DfsioeConfig.getInstance().getReportDir(fsConfig), fs, DfsioeConfig.getInstance().getReportTmp(fsConfig), false, fsConfig, null);”替换为如下内容。
    1 copyMerge(fs, DfsioeConfig.getInstance().getReportDir(fsConfig), fs, DfsioeConfig.getInstance().getReportTmp(fsConfig), false, fsConfig, null);

  f. 在analyzeResult方法前添加2个新的方法，如下所示。
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 @Deprecated public static boolean copyMerge(FileSystem srcFS, Path srcDir, FileSystem dstFS, Path dstFile, boolean deleteSource, Configuration conf, String addString) throws IOException { dstFile = checkDest(srcDir.getName(), dstFS, dstFile, false); if (!srcFS.getFileStatus(srcDir).isDirectory()) return false; OutputStream out = dstFS.create(dstFile); try { FileStatus contents[] = srcFS.listStatus(srcDir); Arrays.sort(contents); for (int i = 0; i < contents.length; i++) { if (contents[i].isFile()) { InputStream in = srcFS.open(contents[i].getPath()); try { IOUtils.copyBytes(in, out, conf, false); if (addString != null) out.write(addString.getBytes("UTF-8")); } finally { in.close(); } } } } finally { out.close(); } if (deleteSource) { return srcFS.delete(srcDir, true); } else { return true; } } private static Path checkDest(String srcName, FileSystem dstFS, Path dst, boolean overwrite) throws IOException { if (dstFS.exists(dst)) { FileStatus sdst = dstFS.getFileStatus(dst); if (sdst.isDirectory()) { if (null == srcName) { throw new IOException("Target " + dst + " is a directory"); } return checkDest(null, dstFS, new Path(dst, srcName), overwrite); } else if (!overwrite) { throw new IOException("Target " + dst + " already exists"); } } return dst; }

  g. 按“Esc”键，输入:wq!，按“Enter”保存并退出编辑。
5. 修改pom.xml文件。
  1 vi hadoopbench/mahout/pom.xml

6. 按“i”进入编辑模式，注释如下代码。
7. 按“Esc”键，输入:wq!，按“Enter”保存并退出编辑。
8. 执行编译。
  1 mvn -Dspark=2.2 -Dscala=2.11 -Dhadoop.mr2.version=3.1.0 clean package
