设为首页 收藏本站
查看: 470|回复: 0

[经验分享] Setting up Apache Solr in Eclipse(转)

[复制链接]
发表于 2016-12-16 07:06:52 | 显示全部楼层 |阅读模式
  在eclipse中建立solr工程的时候,遇到的错误快把我搞崩溃了。先copy这个基本的建立过程。
  by Amit Nithianandan, Senior Search Engineer at Zvents Inc.
  Apache's Solr is a powerful software package that allows you to develop your own search engine in no time. It's purely written in Java using Lucene at its core and can run inside any servlet container such as Tomcat (or Jetty). Eclipse is an IDE that makes developing Java applications incredibly easy because of its wealth of features such as code completion and refactoring capabilities not to mention the number of free plugins available to further make development easier. I find it much easier to keep everything contained in one place and being able to code, debug, and test inside of Eclipse makes developing my search engine much easier. This simple tutorial will show you how to setup Apache Solr to run inside Eclipse using a free third-party plugin that runs Jetty inside Eclipse.
  You will need:
  Eclipse (http://www.eclipse.org).I am using Eclipse 3.4 but this should also work just fine in Eclipse 3.5.
  RunJettyRun plugin (http://code.google.com/p/run-jetty-run/wiki/GettingStarted)
Apache Solr (Any version should suffice. I am using 1.4.)
Step One: Basic Setup
  Download and extract both Eclipse and Apache Solr tar files somewhereon your disk. Since Solr has some XML configuration files, I would alsosuggest installing the Eclipse WTP (Web Toolkit Platform) that gives you some good built-in XML editors.

  Follow the Getting Started guide in the RunJettyRun wiki to install the plugin. It should be pretty fast and easy.
Step Two: Create your Java project
  Create a standard Java project in Eclipse (File..New..Java Project). Call it what you wish (I called it "TestSolr"). The default options should be fine and click through the wizard to see all the options or click Finish at your first chance to get done faster.

  Here you should see your TestProject in your workspace with a blank src folder.
Step Three: Setup the Solr webapp in your Eclipse project.
  This is where the RunJettyRun plugin installed earlier gets used. This plugin allows you to develop, run and debug web applications insideEclipse allowing you to take advantage of Eclipse's powerful code editing and debugging capabilities. It's also one of the simpler web application development plugins available. Eclipse supports full blown web development but for the purposes of this tutorial and developing needs, this plugin is more than enough.

  • Inside the TestSolr directory, create a folder called "webapp". Do this by right clicking on the "TestSolr" in the workspace, select "New" and then "Folder".
  • At a command prompt, unjar the apache-solr-1.4.0.war in this webapp folder. In Windows, this would be done by the following command:
  • jar -xvf c:\applications\apache-solr-1.4.0\dist\apache-solr-1.4.0.war
  • The contents of the war file should be in the webapp folder. To confirm, right click on the "TestSolr" folder in the Eclipse workspace and select "Refresh."
  • Add all the jar files in the webapp/WEB-INF/lib to the Build Path. This is done by selecting all the jars and right click on any of the jars (while all are selected), select the "Build Path" sub-menu and select "Add to Build Path"


  • Setup a solr home folder inside your project. For purposes of this tutorial, copy the "solr" folder from the "example/" folder in the directory containing solr into the "TestSolr" folder in your Eclipse workspace. By now, your "TestSolr" project layout should look something like this.

Step Four: Let's run this thing!
  Now that you have setup your project, it's time to create a run configuration for Jetty and run this!
  In Eclipse, go to the Run menu and select "Run Configurations...".

  • On the left rail, you should see "Jetty Webapp" as one of the run configuration types. Right click on this and select "New". The project should be "TestSolr" (if not, type in TestSolr in the text box labeled with "Project"). The name of the run configuration is populated with "TestSolr" and can be whatever you wish.
  • The default HTTP port is 8080 and can be left alone if you wish. To conform to Solr tutorials (making copying/pasting links easier, change this to 8983). Delete the HTTPs port 8443 since we aren't doing any SSL access. This will disable the SSL specific fields such as the keystore/password fields.
  • Change the "context" to "/solr" from "/". This is more for conformity with the solr tutorials in that all links in the wiki you to something like http://localhost:8983/solr/
  • Type in "webapp" in the "WebApp dir" text box. This is the root of the web application and is the directory above the WEB-INF folder. This is where the solr war file was extracted and hence is the equivalent of deploying the solr war in your servlet container.
  Your launch configuration should look like the following:

  Now click the "Run" button which will save the changes and the console will hopefully start spewing out logs produced by both Jetty andSolr. Open a browser to http://localhost:8080/solr/admin/and voila! you should see the Solr admin page. In scrolling through theconsole, you shouldn't see any exceptions thrown.
  This simple tutorial just shows the basics of setting up a simple solr installation inside Eclipse using Jetty and running inside Eclipse.Notice that we don't have any of our own code running that may do some extra things (say custom analyisis, tokenizing etc). If we did have suchcode, then it would naturally lie in the "src/" folder; however, we need to instruct Eclipse to compile the code so that it goes in the WEB-INF/classes folder so it will run inside Jetty. To do this:

  • Right click on the TestSolr project and select "Properties".
  • Click on the "Java Build Path" on the left rail
  • Click on the "Source" tab and towards the bottom, change the defaultoutput folder to be "TestSolr/webapp/WEB-INF/classes".

  Now you can develop your custom solr plugins directly in Eclipse and debug them immediately. Instead of running the TestSolr jetty instance, you can launch it in debug mode by going to the Run Menu and opening the"Debug Configurations.." sub-menu, selecting the Jetty configuration created earlier and click the "Debug" button. I would encourage familiarizing yourself with Eclipse's debugging capabilities for they are vast and amazing.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-314815-1-1.html 上篇帖子: php + solr 构建自己的企业级搜索应用 下篇帖子: solr的example发布到tomcat下报错
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表