The demo that comes with javase4.0 has a bug. This article describes how to deploy the demo.
Prerequisites: JDK, tomcat, and eclipse (EE) are installed, and Lucene 4.0 compressed files and source code files are downloaded.
1. Create a dynamic web project in eclipse
2. Copy the contents in the lucene-4.0.0-src \ lucene-4.0.0 \ demo \ SRC \ Java folder to the src directory of the eclipse Project
3. overwrite the content in the lucene-4.0.0-src \ lucene-4.0.0 \ demo \ SRC \ resources \ org \ apache \ Lucene \ demo \ xmlparser to the content in the Eclipse project's webcontent folder
4. Copy lucene-analyzers-common-4.0.0.jar, lucene-core-4.0.0.jar, lucene-queries-4.0.0.jar, lucene-queryparser-4.0.0.jar, lucene-sandbox-4.0.0.jar to the webcontent \ Lib folder of the eclipse Project
5. Modify the Eclipse project's webcontent \ WEB-INF \ WEB. xml file to the red part:
<?xml version="1.0" encoding="UTF-8"?><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><display-name>LuceneXmlQueryWebDemo</display-name><servlet><description>Servlet demonstrating XMLQueryParser</description><display-name>FormBasedXmlQueryDemo</display-name><servlet-name>FormBasedXmlQueryDemo</servlet-name><servlet-class>org.apache.lucene.demo.xmlparser.FormBasedXmlQueryDemo</servlet-class><init-param><description>Name of query file held in /WEB-INF</description><param-name>xslFile</param-name><param-value>query.xsl</param-value></init-param><init-param><description>Default field used in standard Lucene QueryParser used in UserQuery tag</description><param-name>defaultStandardQueryParserField</param-name><param-value>jobDescription</param-value></init-param></servlet><servlet-mapping><servlet-name>FormBasedXmlQueryDemo</servlet-name><url-pattern>/FormBasedXmlQueryDemo</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>
The entire project structure is as follows:
6. Export the war file and place it in the Tomcat webapp directory.
7. Enter http: // localhost: 8080/Lucene/in the browser and search for Lucene. The page is as follows: