1、源码地址
http://archive.apache.org/dist/kafka/0.10.0.0/kafka-0.10.0.0-src.tgz
2、环境准备
centOS
gradle 下载地址 https://services.gradle.org/distributions/gradle-3.1-bin.zip 安装请参考 这里 。注意要安装3.1版本,如果安装1.1版本可能会出错。
Scala
Java
3、生成idea项目文件
解压kafka-0.10.0.0-src.tgz
进入目录,执行gradle idea
4、使用idea导入项目并启动
kafka项目启动的入口类是core/src/main/scala/kafka/Kafka
启动需要添加server.properties配置文件路径。
记得修改server.properties里面的内容
然后,这样启动是不会打印日志的,所以要添加log4j.properties文件。在config文件夹下有log4j.properties文件,在core项目下创建resources文件夹,把log4j.properties文件复制过去。
然后启动项目,这样就可以看到打印日志了。(记得修改server.properties里的zk地址和logDir地址)
5、问题:
执行gradle idea时,报错
[root@bigdata01 kafka-0.10.0.0-src]# gradle idea
Starting a Gradle Daemon (subsequent builds will be faster)
Building project 'core' with Scala version 2.10.6
FAILURE: Build failed with an exception.
* Where:
Build file '/opt/bigdata/kafka/kafka-0.10.0.0-src/build.gradle' line: 230
* What went wrong:
A problem occurred evaluating root project 'kafka-0.10.0.0-src'.
> Failed to apply plugin [class 'org.gradle.api.plugins.scala.ScalaBasePlugin']
> No such property: useAnt for class: org.gradle.api.tasks.scala.ScalaCompileOptions
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 22.997 secs
解决方法:vim kafka-0.10.0.0-src/build.gradle文件
添加如下行
ScalaCompileOptions.metaClass.daemonServer = true
ScalaCompileOptions.metaClass.fork = true
ScalaCompileOptions.metaClass.useAnt = false
ScalaCompileOptions.metaClass.useCompileDaemon = false
执行gradle idea时,报错
FAILURE: Build failed with an exception.
* Where:
Build file '/opt/bigdata/kafka/kafka-0.10.0.0-src/build.gradle' line: 48
* What went wrong:
Could not compile build file '/opt/bigdata/kafka/kafka-0.10.0.0-src/build.gradle'.
> startup failed:
build file '/opt/bigdata/kafka/kafka-0.10.0.0-src/build.gradle': 48: unable to resolve class ComponentSelection
@ line 48, column 19.
rules.all { ComponentSelection selection ->
^
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 9.076 secs
我之前安装的是1.1版本的Gradle。换成3.1版本后,问题解决。