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 Windows 7

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

Pre Requirements
1 – Machine with Windows OS (Windows 7,8,Xp.. ..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 make sure it is ready to start.
  • Install Solr4.0 distribution package apache-solr-4.0.0.zip and unzip it in your local directory like C:\apache-solr-4.0.0.
  • Make a folder with name solr-home in your local machine like C:\solr-home.
  • Go back to the solr distribution package that you downloaded C:\apache-solr-4.0.0. Have a peek inside the Examples folder. Copy all those files into the C:\solr-home folder.
  • Look into C:\solr-home\solr and you will see two folders with name collection1 and bin, copy these two folders a step up to C:\solr-home.
  • Look into C:\apache-solr-4.0.0\contrib\extraction in downloaded solr package and you will get a lib folder here , copy this folder to C:\solr-home.
  • Go to C:\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 C:\solr-home\lib
  • Create a file with name data-conf.xml  in C:\solr-home\collection1\conf and add your database details to it like
<dataConfig>

<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" />
</entity>
</document>
</dataConfig>
  • Add this file entry to C:\solr-home\collection1\conf\solr-config.xml file like</requestHandler>
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
  • Copy apache-solr-4.0.war from C:\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 C:\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-name>solr/home</env-entry-name>
<env-entry-value> /Path/To/My/solr/Home/solr/</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry> -->
uncomment the entry and add your solr-home path C:\solr-home to /home/javaguys/solr-home/collection1/confsolr-config.xml file under <config> tag.
  • Add your new libraries location to C:\solr-home\collection1\conf\solr-config.xml.  just under <config>  tag like <lib dir="C:\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 Ubuntu Linux
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



19 comments:

  1. Good Article,Thanks

    ReplyDelete
  2. Its worth's fine

    ReplyDelete
  3. Not sure about 4.0, but I am trying with 4.3 there are two steps missing. I thought it would be helpful if I add that here.

    1. We need to add slf4j configuration, basically copying some jar files.
    2. Adding log4j.properties, without this we do not have any clue what is happening in the system.

    ReplyDelete
  4. Thsi is really helpful blog, mosto of the stuff is covered here.

    ReplyDelete
  5. probably the most complete step by step tutorial.thanks for all the effort.
    I guess PVKR's problem is right,although I didn't face it since I had faced those errors earlier on and had added the required slfj jars into my tomcat lib directly.
    maybe add those two steps and this article will be complete.
    Many thanks once again.
    -Chetan

    ReplyDelete
  6. Thanks for this beautiful article. I read comments section related to logging. I still did not figure what jars to copy, copy from where etc... Found this info from another link. Adding it here as this article which helped me in setting solr locally quick.


    http://wiki.apache.org/solr/SolrLogging

    To get the same logging setup in another container (Tomcat for example) as with the example Jetty server, you need to do the following
    1.
    Copy the jars from solr/example/lib/ext into your container's main lib directory. These jars will set up SLF4J and log4j.
    a.
    Exactly where this lib directory is highly variable. For a Debian or Ubuntu server using the Tomcat package available from the OS vendor, this is likely to be /usr/share/tomcat6/lib or /usr/share/tomcat7/lib.


    2.
    Copy the logging config from solr/example/resources/log4j.properties into a location on the classpath. Usually you can use the same location as the jar files above. Edit the configuration file for your preferred log destination.

    3.
    Optionally, if you did not place log4j.properties on the classpath, set java option -Dlog4j.configuration=file:///path/to/log4j.properties


    If the system can not find the jars for logging, you may get an error which prevents Solr from deploying. For instance in Tomcat 6, it might look like this:


    INFO: Deploying web application archive solr.war
    May 29, 2013 3:59:40 PM org.apache.catalina.core.StandardContext start
    SEVERE: Error filterStart
    May 29, 2013 3:59:40 PM org.apache.catalina.core.StandardContext start
    SEVERE: Context [/solr] startup failed due to previous errors

    If the system cannot find your logging configuration, you may get errors like this:
    log4j:WARN No appenders could be found for logger (org.apache.solr.servlet.SolrDispatchFilter).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

    It might help to start the server with -Dlog4j.debug=true to see more details.

    ReplyDelete
  7. hello

    this is very helpful article and i've just started to learn solr, tomcat as a php developer.

    so i applied all instructions as you said so.

    but i couldn't handle this problem.

    any ideas on this?

    collection1: java.io.IOException:java.io.IOException: Can't find resource 'solrconfig.xml' in classpath or 'solr\collection1\conf/', cwd=C:\tomcat\bin

    ReplyDelete
  8. Hi This is very help full nice explanation with example configurations. We are looking for more articles from you.

    Can you please write article for how to do the automatic indexing.

    ReplyDelete
  9. uncomment the entry and add your solr-home path C:\solr-home to /home/javaguys/solr-home/collection1/confsolr-config.xml file under tag.
    Add your new libraries location to C:\solr-home\collection1\conf\solr-config.xml. just under tag like .

    I haven't understood this step..can you please elaborate!

    ReplyDelete
  10. uncomment the entry and add your solr-home path C:\solr-home to /home/javaguys/solr-home/collection1/confsolr-config.xml file under tag.
    Add your new libraries location to C:\solr-home\collection1\conf\solr-config.xml. just under tag like .
    uncomment the entry and add your solr-home path C:\solr-home to /home/javaguys/solr-home/collection1/confsolr-config.xml file under tag.
    Add your new libraries location to C:\solr-home\collection1\conf\solr-config.xml. just under tag like .

    I haven't understood this step..Please elaborate

    ReplyDelete
  11. can anyone please reply to the comments....even i am not getting that point clear...uncomment the entry and add your solr-home path C:\solr-home to /home/javaguys/solr-home/collection1/confsolr-config.xml file under tag.
    Add your new libraries location to C:\solr-home\collection1\conf\solr-config.xml. just under tag like .

    ReplyDelete
  12. "Copy the logging config from solr/example/resources/log4j.properties into a location on the classpath. Usually you can use the same location as the jar files above. Edit the configuration file for your preferred log destination."

    what does "classpath" refer to...over here???

    ReplyDelete
  13. Hi ,

    Uncomment below section from web.xml file under tomcat installation and add solr home directory path..

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  14. I read the comments but still don't understand:


    At the step of adding [solr-home] as lib into "solr-config.xml", it's stated to add the line under "" tag. As the "solr-config.xml" that was given in the tutorial contains no such tag, what should actually be done?


    Appreciate your work, thanks!

    ReplyDelete
  15. I think I got it: there was already a file called "solrconfig.xml" so I only changed the contents of that file (also duplicated it into "solr-conf.xml" for safe measure)

    ReplyDelete
  16. I was extremely suffering to understand apache tom cat concept. Your content cleared all my doubts and myths. Thanks for sharing.

    Hadoop Course
    in Chennai

    ReplyDelete

Like Us on Facebook


Like Us On Google+



Contact

Email: neel4soft@gmail.com
Skype: neel4soft