【问题标题】:How to set classpath for lucene jar files如何为 lucene jar 文件设置类路径
【发布时间】:2015-04-04 17:36:15
【问题描述】:

我正在使用 Lucene 并尝试为 Lucene 5.0.0 演示 API 中提到的四个 jar 文件设置类路径 “您需要四个 JAR:Lucene JAR、queryparser JAR、通用分析 JAR 和 Lucene 演示 JAR。

将所有这四个文件放在您的 Java CLASSPATH 中。

我正在尝试通过在类路径环境变量中输入以下变量值来设置类路径变量 "F:\Academic\KAU_ResearchGroups\PlagiarismDetection\Lucene\lucene-5.0.0\core; F:\Academic\KAU_ResearchGroups\PlagiarismDetection\Lucene\lucene-5.0.0\queryparser; F:\Academic\KAU_ResearchGroups\PlagiarismDetection\Lucene\ lucene-5.0.0\analysis\common; F:\Academic\KAU_ResearchGroups\PlagiarismDetection\Lucene\lucene-5.0.0\demo;

但是每当我运行以下命令时: java org.apache.lucene.demo.IndexFiles -docs {path-to-lucene}/src

我收到错误消息“错误:无法找到或加载主类 org.apache.lucene.IndexFiles”。

我该如何解决这个问题

【问题讨论】:

    标签: java apache jar lucene classpath


    【解决方案1】:

    看起来您添加到类路径的内容不正确。直接添加罐子,如instructions of the IndexFiles demo:

    F:\Academic\KAU_ResearchGroups\PlagiarismDetection\Lucene\lucene-5.0.0\core\lucene-core-5.0.0.jar; ...

    或者用通配符添加整个目录(见Setting multiple jars in java classpath):

    F:\Academic\KAU_ResearchGroups\PlagiarismDetection\Lucene\lucene-5.0.0\core\*; ...

    【讨论】:

      【解决方案2】:

      你永远不应该相信他们,上传以前的版本,当我使用 Lucene 时,我总是遇到这种类型的错误,所以我上传了从第一个到最后一个的所有 lucen 版本(lucen1.9,lucene 2..... ., Lucene 3.3, lucene 4) 我将它们添加为罐子,直到现在我不知道是哪一个解决了问题;) 使用时不用担心函数声明的区别,可以使用这样的版本 查询 q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);

      祝你好运

      【讨论】:

      • 类路径中的 lucene 版本不匹配可能是导致错误的原因。您通过安装一堆旧版本的 lucene 解决了一个问题,这一事实令人费解。使用 Version.LUCENE_40 之类的方法将旧版本传递给方法调用会指示它使用内置于 current 版本的 lucene 中的兼容性逻辑,而不是在类路径中加载旧 jar。那样不行。
      猜你喜欢
      • 1970-01-01
      • 2020-06-07
      • 2012-02-06
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      相关资源
      最近更新 更多