Eclipse Setup
- Checkout kafka source
- git clone http://git-wip-us.apache.org/repos/asf/kafka.git kafka
- Update the libraries:
- ./sbt update
- Install the eclipse/scala 2.9.x plugin as described here. Make sure to get the right bundle / update site according with your Eclipse version.
- Create a new scala project File->New->Scala Project
- Set the location to the directory to which you checked out the code and choose a name for the project.
- Select the source directories you want, at least:
- core/src/main/scala
- core/src/test/scala/unit
- Select the source directories you want, at least:
- Add all the libraries in the Libraries tab: core/lib and core/lib_managed
- I had to also add the 2.9.1 scala library by choosing Add External Jar and choosing that library
You should be able to run unit tests or the kafka server or other command line apps through eclipse for debugging. To do this right-click the class you want to run and select
-
- Run as...<Unit Test|Scala Application>
- By default log4j will not be configured correctly. To fix this go to your run target and under Classpath choose Advanced... and then Add Folders, and the folder config/
Eclipse Setup With SBT Eclipse Plugin
The following steps assume you have the kafka source and installed the Eclipse Scala IDE, as stated in the Eclipse Setup section above.
- edit the project/plugins.sbt file by adding the
sbteclipse-plugin
from Typesafe (last line in the snippet below). Once modified, the file should look like this:resolvers += Resolver.url("artifactory", url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns) addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.5") addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0") addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.1")
- run:
./sbt update
- generate the eclipse projects with:
./sbt eclipse
. This command will create eclipse projects for every project defined in Kafka. You should have the following output on your console:[info] About to create Eclipse project files for your project(s). [info] Successfully created Eclipse project files for project(s): [info] kafka-perf [info] hadoop-consumer [info] kafka-java-examples [info] kafka [info] hadoop-producer
- In eclipse, use Import -> General -> Existing Projects into Workspace
- navigate to the kafka source directory, it should find the projects generated by the previous command.
- select the projects you want to import and click Finish
- you should see the projects you have imported
Once you have your projects in place, you will be able to run/debug any of the applications from eclipse.
You will need regenerate the projects and refresh eclipse every time there is a change in the projects dependencies. In other words, every time you run ./sbt update
, you need to run ./sbt eclipse
and refresh eclipse.
Intellij Setup
- Checkout kafka source
- git clone http://git-wip-us.apache.org/repos/asf/kafka.git kafka
- Update the libraries:
- ./sbt update
- Create IDEA project files:
- ./sbt
- idea
- Install the IntelliJ IDEA Scala Plugin Preferences -> Plugins -> Browse Repositories -> Search for Scala||\
- Open Itellij, Open new project, point to your kafka source location.