Java and J2EE Tutorials, Jsp and Servlet Tutorials, Spring MVC, Solr, XML, JSON Examples, Hibernate & Struts 2 Hello World projects

Saturday, 19 January 2013

Apache Solr 4.0 with Apache Tomcat 7 in Ubuntu Linux

If you want to configure Solr4.0.0 in Windows environment please click here.
In this blog i will tell you how to integrate Solr4.0 with apache-tomcat 7 in linux environment. Before we start i recommend you to read an Introduction of solr4.0 from here.

Pre Requirements
1 – Machine with Linux (Ubuntu, fedora ..etc)
2 – Java 6 or Above
3 - Solr 4.0.0 or Above
4 – Apache-tomcat 7 or Above.

Steps to get Solr up on Tomcat Server
  • Install Tomcat on your machine and and make sure it is ready to start.
  • Install Solr4.0 distribution package apache-solr-4.0.0.tgz and unzip it in your local directory like /home/javaguys/apache-solr-4.0.0.
  • Make a folder with name solr-home in your local machine like /home/javaguys/solr-home.
  • Go back to the solr distribution package that you downloaded /home/javaguys/apache-solr-4.0.0. Have a peek inside the Examples folder. Copy all those files into the /home/javaguys/solr-home folder.
  • Look into /home/javaguys/solr-home/solr and you will see two folders with name collection1 and bin, copy these two folders a step up to /home/javaguys/solr-home.
  • Look into /home/javaguys/apache-solr-4.0.0/contrib/extraction in downloaded solr package and you will get a lib folder here , copy this folder to /home/javaguys/solr-home.
  • Go to /home/javaguys/apache-solr-4.0.0/dist and copy apache-solr-dataimporthandler-extras-4.0.0.jar, apache-solr-dataimporthandler-4.0.0.jar and apache-solr-cell-4.0.0.jar to home/javaguys/solr-home/lib
  • Create a file with name data-conf.xml  in /home/javaguys/solr-home/collection1/conf and add your database details to it like

<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/javaguysDB" user="root" password="root" batchSize="1" />

<document name="emp">

<entity name="emp_details" query="SELECT * FROM emp_details">
<field column="id" name="id" />
<field column="name" name="name" />
<field column="address" name="address" />
<field column="details" name="details" />


Add this file entry to /home/javaguys/solr-home/collection1/conf/solr-config.xml file like
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>

Copy apache-solr-4.0.war from /home/javaguys/apache-solr-4.0.0/dist directory to webapps directory inside Tomcat.
Start your Tomcat and check webapps directory having one new directory added with name solr.
Look inside /home/javaguys/apache-tomcat-6.0.36/webapps/solr/WEB-INF and open web.xml in a text editor, now look for an entry like this
<!-- <env-entry>
<env-entry-value> /Path/To/My/solr/Home/solr/</env-entry-value>
</env-entry> -->
uncomment the entry and add your solr-home path /home/javaguys/solr-home to value tag.
  • Add your new libraries location to /home/javaguys/solr-home/collection1/conf/solr-config.xml.  just under <config>  tag like <lib dir="/home/javaguys/solr-home/lib" />.
And you are all done with it , start your server to localhost:8080/solr and you will get your solr admin panel up.

In upcoming blogs we will see how to make queries to solr server and other important stuff with solr 4.0.0.

Introduction to Apache Solr 4.0 with Apache Tomcat
Apache Solr 4.0 with Apache Tomcat 7 in Windows 7
How to integrate Highlighting in Search Results Using Apache solr4 and apache tomcat
How to use the Solr Data Import Handler to index a MySQL database table

Thanks for reading !
Being Java Guys Team


  1. Thanks that is super helpful!

  2. I have installed the solr 4.3.0 on apache-tomcat-7.0.39 and configured the way you stated above but it is not working, pleasee help me to setup the solr

    1. hello vaibhav ! can you please tell me the problems that u r facing .. so that i could help u accordingly.

    2. I use this tuto with tomcat7 & sol-4.3 and it works, only need to add this as extra:

      cp solr-4.3.0/example/lib/ext/* /path/to/apache-tomcat-7/lib/

      Hope it helps.

  3. Thx for the great tutorial :)
    you've saved my day :D

  4. i believe this should also work on tomcat 6

  5. Thank You,
    the tutorial helped me a lot

  6. I am not getting admin page
    I am getting this error
    HTTP Status 500 - {msg=SolrCore 'collection1' is not available due to init failure: Could not load config file /home/vardhan/solr-home/collection1/solrconfig.xml,trace=org.apache.solr.common.SolrException: SolrCore 'collection1' is not available due to init failure: Could not load config file /home/vardhan/solr-home/collection1/solrconfig.xml

  7. I'm not clear how to tell Tomcat where image files are located.


Like Us on Facebook

Like Us On Google+


Skype: neel4soft