Java程序使用或覆盖不推荐使用的API?

我编写了一个在Netbeans和Eclipse中编译和运行的程序没有任何问题。 但是当我尝试通过命令行编译它时:

javac -classpath .:lucene-core-3.4.0.jar Indexer.java 

我收到错误:

 Note: Indexer.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 

当我尝试使用-Xlint编译时:弃用选项我得到:

 javac -classpath .:lucene-core-3.4.0.jar Indexer.java -Xlint:deprecation Indexer.java:14: warning: [deprecation] org.apache.lucene.index.IndexWriter.MaxFieldLength in org.apache.lucene.index.IndexWriter has been deprecated import org.apache.lucene.index.IndexWriter.MaxFieldLength; ^ 1 warning 

我的源代码似乎是纯粹的,没有任何问题! 谁能帮我编译并在命令行中运行它?

 import java.io.File; import java.io.FileFilter; import java.io.FileReader; import java.io.IOException; import java.io.File; import java.io.FileReader; import java.io.BufferedReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter.MaxFieldLength; import org.apache.lucene.document.Field; import org.apache.lucene.document.Document; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.analysis.StopAnalyzer; import org.apache.lucene.index.IndexReader; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.apache.lucene.index.TermFreqVector; public class Indexer { public static void main(String[] args) throws Exception { // TODO code application logic here //Indexing begins String indexDir; String dataDir; if (args.length != 2) { dataDir = new String("/home/norc/Ranking/Hamshahri/Data/"); indexDir = new String("/media/5E62D9BD62D99A5B/indexes/"); //throw new IllegalArgumentException("Usage: java " + Indexer.class.getName() + "  "); } else { dataDir = args[0]; indexDir = args[1]; } long start = System.currentTimeMillis(); Indexer indexer = new Indexer(indexDir); int numIndexed; try { numIndexed = indexer.index(dataDir, new TextFilesFilter()); } finally { indexer.close(); } long end = System.currentTimeMillis(); System.out.println("Indexing " + numIndexed + " files took " + (end - start) + " milliseconds"); } private IndexWriter writer; @SuppressWarnings("deprecation") public Indexer(String indexDir) throws IOException { Directory dir = FSDirectory.open(new File(indexDir)); writer = new IndexWriter(dir, new StopAnalyzer(Version.LUCENE_34, new File("/home/norc/Ranking/Hamshahri/stopwords.txt")), true, IndexWriter.MaxFieldLength.UNLIMITED); } public void close() throws IOException { writer.close(); } public int index(String dataDir, FileFilter filter) throws Exception { File[] dires = new File(dataDir).listFiles(); for (File d: dires) { if (d.isDirectory()) { File[] files = new File(d.getAbsolutePath()).listFiles(); for (File f: files) { if (!f.isDirectory() && !f.isHidden() && f.exists() && f.canRead() && (filter == null || filter.accept(f))) { indexFile(f); } } } } return writer.numDocs(); } private static class TextFilesFilter implements FileFilter { public boolean accept(File path) { return path.getName().toLowerCase().endsWith(".txt"); } } protected Document getDocument(File f) throws Exception { Document doc = new Document(); if (f.exists()) { doc.add(new Field("contents", new FileReader(f), Field.TermVector.YES)); doc.add(new Field("path", f.getAbsolutePath(), Field.Store.YES, Field.Index.NOT_ANALYZED)); String cat = "WIR"; cat = f.getAbsolutePath().substring(0, f.getAbsolutePath().length()-f.getName().length()-1); cat = cat.substring(cat.lastIndexOf('/')+1, cat.length()); //doc.add(new Field("category", cat.subSequence(0, cat.length()), Field.Store.YES)); //System.out.println(cat.subSequence(0, cat.length())); } return doc; } private void indexFile(File f) throws Exception { System.out.println("Indexing " + f.getAbsolutePath()); Document doc = getDocument(f); writer.addDocument(doc); } } 

org.apache.lucene.index.IndexWriter.MaxFieldLength已弃用,不应再使用,请参阅https://lucene.apache.org/core/old_versioned_docs/versions/3_4_0/api/all/org/apache/lucene/索引/ IndexWriter.MaxFieldLength.html#IndexWriter.MaxFieldLength%28int%29

这只是一个警告。 您可以使用它,但不建议使用它。