人人站cms,关键词优化师,网页游戏如何制作,公司网站开发费用济南兴田德润o简介图片使用Maven运行Solr Solr是一个开放源代码搜索服务器#xff0c;它是使用Lucene Core的索引和搜索功能构建的#xff0c;它可以用于使用几乎任何编程语言来实现可扩展的搜索引擎。 尽管Solr具有许多优点#xff0c;但建立一个开发环境并不是其中之一。 该博客文章描述了如何… 使用Maven运行Solr Solr是一个开放源代码搜索服务器它是使用Lucene Core的索引和搜索功能构建的它可以用于使用几乎任何编程语言来实现可扩展的搜索引擎。 尽管Solr具有许多优点但建立一个开发环境并不是其中之一。 该博客文章描述了如何使用Maven运行Solr并确保每个开发人员都使用相同的配置架构和Solr版本。 我们的Maven构建的要求如下 我们的Maven构建的属性必须从外部属性文件中读取。 该规则的唯一例外是依赖项的版本号在我们的POM文件中声明。 启动我们的Solr实例时构建过程必须将Solr配置文件复制到正确的目录。 当开发人员在命令提示符下执行mvn clean命令时构建过程必须清除配置文件。 必须能够通过使用Jetty Maven插件启动我们的Solr实例。 我们可以通过执行以下步骤来满足这些要求 创建一个POM文件。 获取所需的依赖项。 获取Solr配置文件。 创建属性文件其中包含在我们的Maven构建中使用的属性。 编辑solr.xml文件。 配置属性Maven插件。 配置复制Maven插件。 配置Jetty Maven插件。 下面将更详细地描述这些步骤。 创建POM文件 首先我们必须为Web应用程序项目创建POM文件。 我们的POM文件的框架如下所示 project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdmodelVersion4.0.0/modelVersiongroupIdnet.petrikainulainen.maven/groupIdartifactIdrunning-solr-with-maven/artifactIdpackagingwar/packagingversion0.1/versionprofiles!-- Add profile configuration here --/profilesdependencies!-- Add dependencies here --/dependenciesbuildfinalNamesolr/finalName!-- Add filter configuration here --!-- Add resources configuration here --plugins!-- Add plugin configuration here --/plugins/build
/project获取所需的依赖关系 我们唯一需要的依赖是Solr 4.1.0战争。 换句话说我们唯一要做的就是将以下依赖项声明添加到POM文件的依赖项部分 dependencygroupIdorg.apache.solr/groupIdartifactIdsolr/artifactIdversion4.1.0/versiontypewar/type
/dependency获取Solr配置文件 通过执行以下步骤我们可以获取Solr配置文件 下载Solr 4.1.0的二进制发行版 。 将下载的软件包解压缩到所需目录。 进入解压缩的Solr二进制发行版的根目录。 将以下文件从目录example / solr / collection1 / conf复制到目录src / main / config admin-extra.htmladmin-extra-menu.menu-bottom.htmladmin-extra.menu-top.hml currency.xmlelevate.xmlmapping-FoldToASCII.txtmapping-ISOLatin1Accent.txtprotwords.xmlschema.xmlsolrconfig.xmlspellings.txtstopwords.txt同义词.txt和update-script.js 。 将从目录example / solr / collection1 / conf / lang找到的特定于语言的配置文件复制到目录src / main / config / lang中 。 将从目录example / solr / collection1 / conf / velocity目录中找到的Velocity宏和其他文件复制到目录src / main / config / velocity中 。 将从目录example / solr / collection1 / conf / xslt中找到的XSL样式表复制到目录src / main / config / xslt中 。 将solr.xml文件从目录exaple / solr / collection1复制到目录src / main / resources 。 创建目录src / main / webapp / WEB-INF 。 此目录是必需的以便可以启动Solr实例。 现在我们已经成功获取了所需的文件并准备进行下一个阶段。 创建属性文件 接下来是创建在Maven构建中使用的属性文件并将所需的构建配置文件配置添加到我们的POM文件中。 让我们继续前进找出实现方法。 首先我们创建了在Maven构建中使用的属性文件。 我们可以按照以下步骤进行操作 将目录profile / dev创建到我们的Maven项目的根目录。 在profiles / dev目录中创建一个属性文件config.properties 。 我们的属性文件具有以下三个属性 solr.detault.core.directory属性指定默认核心目录的值。 这是在我们的Solr实例的主目录下创建的目录。 该目录存储我们的Solr实例及其数据的配置。 solr.default.core.name属性指定默认核心的名称。 solr.solr.home属性指出我们的Solr安装目录的主目录。 config.properties文件的内容如下所示 #SOLR PROPERTIES
#Configures the directory used to store the data and configuration of the Solr default core
solr.default.core.directorytodo
#Configures the name of the Solr default core.
solr.default.core.nametodo#SYSTEM PROPERTIES
#Configures the home directory of Solr. Set the preferred directory path here.
solr.solr.home 其次我们必须配置Maven构建的构建配置文件并使用过滤来替换替换资源中包含的变量。 我们可以按照以下步骤进行操作 创建一个名为dev的配置文件并确保它是我们构建的默认配置文件。 声明一个名为build.profile.id的属性并将其值设置为dev。 创建一个过滤器该过滤器读取特定于配置文件的配置文件并将从我们的资源中找到的变量替换为实际的属性值。 通过将以下配置文件声明添加到我们的POM文件中我们可以完成步骤1和步骤2 profileiddev/idactivationactiveByDefaulttrue/activeByDefault/activationpropertiesbuild.profile.iddev/build.profile.id/properties
/profile 我们可以通过将以下XML添加到POM文件的build部分来完成第三步 filtersfilter${project.basedir}/profiles/${build.profile.id}/config.properties/filter
/filters
resourcesresourcefilteringtrue/filteringdirectorysrc/main/resources/directory/resource
/resources编辑solr.xml文件 因为我们使用特定于配置文件的配置文件来配置Solr默认核心的名称和实例目录所以我们必须对solr.xml文件进行更改。 这些更改描述如下 必须将solr.default.core.name属性的值设置为cores元素的defaultCoreNameAttribute属性的值。 必须将solr.default.core.name属性的值设置为核心元素的name属性的值。 必须将solr.default.core.directory属性的值设置为核心元素的instanceDir属性的值。 solr.xml文件的内容如下所示 solr persistenttruecores adminPath/admin/cores defaultCoreName${solr.default.core.name} host${host:} hostPort${jetty.port:} hostContext${hostContext:} zkClientTimeout${zkClientTimeout:15000}core name${solr.default.core.name} instanceDir${solr.default.core.directory} //cores
/solr配置属性Maven插件 因为我们希望从外部属性文件中读取POM文件中使用的所有属性值所以我们必须使用名为Properties Maven plugin的插件 。 我们可以按照以下步骤配置此插件 确保从配置文件特定的配置文件中读取属性。 创建一个执行该执行在Maven默认生命周期的初始化阶段中运行Properties Maven插件的read-project-properties目标。 创建一个执行该执行在Maven清理生命周期的预清理阶段中运行Properties Maven插件的读取项目属性目标。 Properties Maven插件的配置如下所示 plugingroupIdorg.codehaus.mojo/groupIdartifactIdproperties-maven-plugin/artifactIdversion1.0-alpha-2/versionconfigurationfiles!-- Properties are read from profile specific property file --file${project.basedir}/profiles/${build.profile.id}/config.properties/file/files/configurationexecutions!-- Load properties for the default lifecycle --executioniddefault-lifecycle-properties/idphaseinitialize/phasegoalsgoalread-project-properties/goal/goals/execution!-- Load properties for the clean lifecycle --executionidclean-lifecycle-properties/idphasepre-clean/phasegoalsgoalread-project-properties/goal/goals/execution/executions
/plugin配置复制Maven插件 我们将使用Copy Maven插件有两个目的 启动Solr实例时我们会将Solr配置文件复制到正确的目录中。 在命令提示符处执行命令mvn clean时我们将删除Solr配置文件。 我们可以通过将以下XML添加到POM文件的插件部分来开始使用 plugingroupIdcom.github.goldin/groupIdartifactIdcopy-maven-plugin/artifactIdversion0.2.5/versionexecutions!-- Add executions here --/executions
/plugin 让我们继续前进了解如何配置Copy Maven插件以复制和删除Solr配置文件。 复制Solr配置文件 我们可以按照以下步骤复制Solr配置文件 创建一个执行该执行在Maven默认生命周期的编译阶段中运行Copy Maven插件的复制目标。 将solr.xml文件复制到我们的Solr实例的主目录。 复制文件时请确保将属性过滤应用于文件。 将从src / main / config目录找到的文件复制到solr.solr.home / solr.default.core.directory / conf目录。 将从src / main / config / lang目录中找到的特定于语言的配置文件复制到solr.solr.home / solr.detault.core.directory / conf / lang目录中。 将src / main / config / velocity目录中找到的Velocity宏和其他文件复制到solr.solr.home / solr.detault.core.directory / conf / velocity目录。 将从src / main / config / xslt目录中找到的XSL样式表复制到solr.solr.home / solr.detault.core.directory / conf / xslt目录中。 我们执行的配置如下所示 executionidcopy-solr-config/idphasecompile/phasegoalsgoalcopy/goal/goalsconfigurationresources!--Copy solr.xml to correct directory and applies propertiesfiltering to it.--resourcedirectory${project.basedir}/src/main/resources/directoryfilteringtrue/filteringtargetPath${solr.solr.home}/targetPathincludesincludesolr.xml/include/includes/resource!-- Copy configuration files --resourcedirectory${project.basedir}/src/main/config/directorytargetPath${solr.solr.home}/${solr.default.core.directory}/conf/targetPathexcludesexcludelang/excludeexcludevelocity/excludeexcludexslt/exclude/excludes/resource!-- Copy language specific configuration files --resourcedirectory${project.basedir}/src/main/config/lang/directorytargetPath${solr.solr.home}/${solr.default.core.directory}/conf/lang/targetPath/resource!-- Copy Velocity macros and other files --resourcedirectory${project.basedir}/src/main/config/velocity/directorytargetPath${solr.solr.home}/${solr.default.core.directory}/conf/velocity/targetPath/resource!-- Copy XSL style sheets --resourcedirectory${project.basedir}/src/main/config/xslt/directorytargetPath${solr.solr.home}/${solr.default.core.directory}/conf/xslt/targetPath/resource/resources/configuration
/execution删除Solr配置文件 我们可以按照以下步骤删除Solr配置文件 创建一个执行该执行在干净的生命周期阶段运行Copy Maven插件的复制目标。 如果找不到目录请确保构建不会失败。 删除在我们的Maven项目的根目录中创建的overlays目录。 删除从我们的Solr实例的主目录中找到的solr.xml文件。 删除从solr.solr.home / solr.default.core.directory目录中找到的conf目录。 我们执行的配置如下所示 executionidclean-solr/idphaseclean/phasegoalsgoalcopy/goal/goalsconfigurationfailIfNotFoundfalse/failIfNotFoundresources!-- Clean the overlays directory from the project root directory --resourcecleantrue/cleancleanEmptyDirectoriestrue/cleanEmptyDirectoriesdirectory${project.basedir}/overlays/directoryincludesinclude**/**/include/includes/resource!-- Remove the solr.xml file --resourcecleantrue/cleandirectory${solr.solr.home}/directoryincludesincludesolr.xml/include/includes/resource!-- Remove the conf directory --resourcecleantrue/cleancleanEmptyDirectoriestrue/cleanEmptyDirectoriesdirectory${solr.solr.home}/${solr.default.core.directory}/directoryincludesincludeconf/include/includes/resource/resources/configuration
/execution配置Jetty Maven插件 我们可以按照以下步骤配置Jetty Maven插件以运行Solr实例 配置Jetty侦听端口8983。 确保从配置文件特定的配置文件中读取系统属性。 该属性文件包含一个名为solr.solr.home的属性该属性指定我们的Solr实例的主目录。 指定我们应用程序的上下文路径为/ solr 。 Jetty Maven插件的配置如下所示 plugingroupIdorg.mortbay.jetty/groupIdartifactIdjetty-maven-plugin/artifactIdversion8.1.8.v20121106/versionconfigurationstopPort9966/stopPortstopKeystop/stopKeyconnectors!-- Listen to port 8983 --connector implementationorg.eclipse.jetty.server.nio.SelectChannelConnectorport8983/portmaxIdleTime60000/maxIdleTime/connector/connectors!-- Read system properties from profile specific configuration file --systemPropertiesFile${project.basedir}/profiles/${build.profile.id}/config.properties/systemPropertiesFilewebAppcontextPath/solr/contextPath/webApp/configuration
/plugin运行Solr 现在我们已经创建了一个Maven构建该构建可用于在开发环境中运行Solr。 启动Solr实例有两种选择 我们可以在命令提示符下执行mvn jettyrun命令。 我们可以在命令提示符下执行mvn jettyrun-war命令。 启动Solr之后我们可以使用以下URL地址访问其管理界面 http// localhost8983 / solr 。 Github提供了示例应用程序 。 本示例使用自定义架构因为我计划在Spring Data Solr教程中使用它。 原始示例架构可从etc目录中找到。 参考来自Petri Kainulainen博客的JCG合作伙伴 Petri Kainulainen 与Maven一起运行Solr 。 翻译自: https://www.javacodegeeks.com/2013/05/running-solr-with-maven.html