Wednesday, May 18, 2016

How to Download and Compile Solr 6 in Eclipse

Overview

  • Download and install the Oracle Java SE JDK
  • Download and Install Eclipse
  • Download and Install Apache Ant
  • Download Solr source code
  • Prepare Solr source code for Eclipse environment
  • Importing and compiling Solr source in Eclipse
  • Using the Build.xml files in the Project


Download and install the Oracle Java SE JDK

  1. For Solr 6.0.0, you need at least Java SE 8
  2. I chose to install the Windows x64 product
  3. Make sure that java is accessible from the command line
    1. Open a new command window
    2. type: java -version
You should see something like:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)


The JDK automatically installs the JRE, so you don't need to install them separately.

Download and Install Eclipse

  1. Go to the Eclipse download page and download the version that's right for you (I chose 64-bit Eclipse IDE for Java Developers)
    NOTE: If you installed the 64-bit JDK, you'll need to install the 64-bit version of Eclipse.  If you installed the 32-bit version, you'll need to download the 32-bit version of Eclipse.
  2. All you need to do in order to install Eclipse is to extract it to where you want it to live--I chose D:\eclipse64
  3. Open that folder and double-click eclipse.exe
  4. When asked to set the workspace, I chose D:\eclipse_workspace

Download and Install Apache Ant

  1. Download page
  2. I downloaded the .zip archive
  3. I chose to extract it to C:\Apache\ant-1.9.7
  4. Add Apache Ant's bin directory to your PATH environment variable (C:\Apache\ant-1.9.7\bin)

Download Solr source code

  1. I used this link to download the tgz source file (they didn't have a ZIP version of the source at this time).  If that link isn't available, then go to the Solr latest redirect page.
  2. Since I'm on Windows, I needed to download 7-Zip (I used the 64-bit version)
  3. Extract the source (I will use D:\solr, which should generate a D:\solr\solr-6.0.0 folder)

Prepare Solr source code for Eclipse environment

  1. Open this folder in Windows Explorer
  2. Shift + Right-Click in the whitespace inside the folder and click Open command window here (or open a command window and cd to your new solr-6.0.0 folder)
  3. ant eclipse
  4. At this point, Solr should be preparing the source for use in Eclipse.  You should see something like this:
    BUILD SUCCESSFUL
    Total time: 
    22 seconds

Importing and compiling Solr source in Eclipse

  1. Go back to Eclipse
  2. File > Import...
  3. Expand General and select Existing Projects into Workspace
  4. Click Browse... next to Select root directory and select the solr root directory (where you extracted the source tgz file)
  5. It should find the solr project and list it in the Projects list below.  Make sure it's selected and click Finish
  6. Eclipse should automatically start building the project (you should see an indicator in the bottom-right corner)
  7. While it's building, click on the Workbench icon at the top-right corner
  8. You should see the Package Explorer on the right-hand side
  9. At the bottom, middle, you should see a Problems tab.  Click on it if it's not the one in focus.
    As it was compiling, I saw a few items get put in there, but they went away by the time it stopped compiling and I was left with 11,156 warnings and 0 errors.
Eclipse should be happy with the compile results, but you will want to do a bit more than Eclipse does when it first imports the code.  Solr makes a lot of use out of Apache Ant, which operates on the build.xml file.

Using the build.xml files in the Project

  1. Expand the solr root folder in the Package Explorer and select the build.xml file
  2. Right-click the build.xml file > Run As > Ant Build...
  3. Uncheck the -projecthelp [default] item at the top of the list
  4. This is how you can trigger the ant targets in Eclipse.  Let's trigger the real compile (as far as solr is concerned).
  5. Check the compile target and click Run
  6. It will probably take a few minutes before you see the BUILD SUCCESSFUL message
  7. Now let's use build.xml in Eclipse to build the server
  8. Expand the solr subfolder and right-click that build.xml (note that this is a subfolder off of the root source folder) > Run As > Ant Build...
  9. Uncheck the usage [default] target
  10. Check server and click Run
  11. That should build the server, which you can then run and index files.
    Check out this article I wrote about this if you want to learn more (you can skip the first part, since you've essentially set up your environment).

Conclusion

Now you're in a good position to get started in development in the Solr community, although you will want to use the git repository to get the latest version.  Getting started can be a bit tough, so starting with a known good source is important, as you can scratch your head for days not knowing why the code doesn't compile--when it just so happened to be a bad check-in.  That's one of the reasons I started by downloading the 6.0.0 source, because it's quite likely that that code compiles.

I owe a huge thank-you to @elyograg from the #solr chat room, who walked me through my Eclipse woes!  It seems as though I was doing everything wrong and this guy set me straight.

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thank you for your slide, I manage to setup.

    ReplyDelete
  3. I can't compile when uncheck -projecthlep and check compile but I put solr.xml file under solr subfolder and it work file.

    BTW I would like to know about that build.xml. Why check compile and server in both build.xml?

    ReplyDelete
    Replies
    1. Build.xml is the thing that knows how to compile all of the different pieces as well as how to piece them all together--depending on your needs. For instance, you can tell it to just compile the code, run tests, and even build the final server so you can deploy it to your running environments.

      See the solr website for more information about the different pieces--or just poke it with a stick and see what happens. :)

      Compile vs. Server
      If I remember correctly, compile only compiles the source code. The separate server step grabs the code and generates the directory structure needed in order to actually run Solr like you would if you downloaded the binary-only version of Solr from the website.

      Developers don't need the server up and running in order to test their pieces with JUnit, etc. They just compile their components and put them through the paces directly.
      But, when we're wanting to have Solr up and running, serving requests as one would normally want, we need to get everything ticked and tied so that Jetty can find everything and bring everything together.

      Thank you for your question.
      Does that help?

      Delete
  4. Hi

    I am not able to fine the sever build option ,i.e setp 10
    can you help
    thanks in advacne

    ReplyDelete
  5. thanks a lot for your detailed steps. This was only article I found that detailed out every required step.

    ReplyDelete