【问题标题】:Can't compile Lucene project with Eclipse无法用 Eclipse 编译 Lucene 项目
【发布时间】:2013-01-26 21:02:51
【问题描述】:

这是我的代码:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.apache.lucene.index.CorruptIndexException;

public class Main 
{
    public static void main()
    {
        //Index index = new Index();
        String[] titleAndContent = parseFile("files/methode.txt");
        Index index = new Index("files",null);
        try 
        {
            index.openIndex(true);
            index.addDocument(titleAndContent[0], titleAndContent[1], "files/methode.txt");
        } 
        catch (CorruptIndexException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public static String[] parseFile(String path)
    {
        String[] titleAndContent = new String[2];
        File file = new File(path);
        try 
        {
            FileReader fr = new FileReader(file); 
            BufferedReader br = new BufferedReader(fr); 
            String line = new String();
            String content = new String();
            try 
            {
                while((line = br.readLine()) != null) 
                { 
                     if (line.substring(0,min(6,line.length())).equals("title:"))
                     {
                         titleAndContent[0] = line.substring(6,line.length());
                     }
                     else
                     {
                         if (line.substring(0,min(8,line.length())).equals("content:"))
                         {
                             content += line.substring(8,line.length())+"\n";
                         }
                         else
                         {
                             content += line+"\n";
                         }
                     }
                }
            } 
            catch (IOException e1) 
            {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            titleAndContent[1] = content;
            try 
            {
                fr.close();
            } 
            catch (IOException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } 
        catch (FileNotFoundException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return titleAndContent;
    }

    public static int max (int a, int b)
    {
        if (a<b)
        {
            return b;
        }
        return a;
    }

    public static int min (int a, int b)
    {
        if (a<b)
        {
            return a;
        }
        return b;
    }
}

问题是,我无法在 Eclipse 下编译我的 Lucene 项目。它一直告诉我:

ERROR: index path not specified

Usage: java org.apache.lucene.index.CheckIndex pathToIndex [-fix] [-segment X] [-segment Y]

  -fix: actually write a new segments_N file, removing any problematic segments
  -segment X: only check the specified segments.  This can be specified multiple
              times, to check more than one segment, eg '-segment _2 -segment _a'.
              You can't use this with the -fix option

**WARNING**: -fix should only be used on an emergency basis as it will cause
documents (perhaps many) to be permanently removed from the index.  Always make
a backup copy of your index before running this!  Do not run this tool on an index
that is actively being written to.  You have been warned!

Run without -fix, this tool will open the index, report version information
and report any exceptions it hits and what action it would take if -fix were
specified.  With -fix, this tool will remove any segments that have issues and
write a new segments_N file.  This means all documents contained in the affected
segments will be removed.

This tool exits with exit code 1 if the index cannot be opened or has any
corruption, else 0.

我尝试了一切来让它发挥作用,正如整个网络所说,我使用了

-ea:org.apache.lucene... pathToIndex -fix

作为编译的参数。但是无论我放什么而不是 pathToIndex,它一直在告诉我

Unexpected argument pathToIndex (or whatever instead)

我怎样才能得到这个f...项目的工作? 提前谢谢你。

编辑:当然我已经导入了所有 Lucene JAR。

【问题讨论】:

  • 从您发布的内容来看,您似乎正在从 Lucene 本身启动 CheckIndex 类。你能显示你的编译命令吗(我不是 Eclipse 人,但必须有一种方法可以查看所有 javac 参数)?

标签: eclipse path lucene indexing


【解决方案1】:

实际上,我通过在其中创建一个简单的 Main 类和一个 main 方法来重新启动项目,并尝试立即编译它。这次它工作得很好。请注意,在 Eclipse 中编译之前,您应该在屏幕选项卡上显示 Main 类。

【讨论】:

    猜你喜欢
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多