gpt4 book ai didi

java - 从命令行错误在 Linux 上编译 Java 应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:29:42 26 4
gpt4 key购买 nike

我是一个 Java 新手,事实上我使用它的唯一原因是因为 lucene。

我在Windows上使用eclipse开发了一个lucene应用程序并工作。所以现在当我尝试从 Linux 命令行编译应用程序时,它不起作用。

这是我的文件夹结构。

search_example/
├── lucene-5.0.0
│   ├── analysis
│   │   └── common
│   │   └── lucene-analyzers-common-5.0.0.jar
│   ├── core
│   │   └── lucene-core-5.0.0.jar
│   ├── queries
│   │   └── lucene-queries-5.0.0.jar
│   └── queryparser
│   └── lucene-queryparser-5.0.0.jar
├── lucene_test
│   ├── IndexFiles.java
│   ├── IndexMarkdown.java
│   ├── SearchFiles.java
│   └── SearchMarkdown.java
└── readme.md

这里是编译调用:

$ cd ~/search_example
$ javac lucene_test/IndexMarkdown.java -classpath ./; lucene-5.0.0/analysis/common/lucene-analyzers-common-5.0.0.jar; lucene-5.0.0/core/lucene-core-5.0.0.jar; lucene-5.0.0/queries/lucene-queries-5.0.0.jar ; lucene-5.0.0/queryparser/lucene-queryparser-5.0.0.jar

我收到以下错误,表明它找不到我作为“类路径”传入的“jar”文件

./lucene_test/IndexFiles.java:20: error: package org.apache.lucene.analysis does not exist
import org.apache.lucene.analysis.Analyzer;
^
./lucene_test/IndexFiles.java:21: error: package org.apache.lucene.analysis.standard does not exist
import org.apache.lucene.analysis.standard.StandardAnalyzer;
^
./lucene_test/IndexFiles.java:22: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.Document;
^
./lucene_test/IndexFiles.java:23: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.Field;
^
./lucene_test/IndexFiles.java:24: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.LongField;
^
./lucene_test/IndexFiles.java:25: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.StringField;
^
./lucene_test/IndexFiles.java:26: error: package org.apache.lucene.document does not exist
import org.apache.lucene.document.TextField;
^
./lucene_test/IndexFiles.java:27: error: package org.apache.lucene.index does not exist
import org.apache.lucene.index.IndexWriter;
^
./lucene_test/IndexFiles.java:28: error: package org.apache.lucene.index.IndexWriterConfig does not exist
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
^
./lucene_test/IndexFiles.java:29: error: package org.apache.lucene.index does not exist
import org.apache.lucene.index.IndexWriterConfig;
^
./lucene_test/IndexFiles.java:30: error: package org.apache.lucene.index does not exist
import org.apache.lucene.index.Term;
^
./lucene_test/IndexFiles.java:31: error: package org.apache.lucene.store does not exist
import org.apache.lucene.store.Directory;
^
./lucene_test/IndexFiles.java:32: error: package org.apache.lucene.store does not exist
import org.apache.lucene.store.FSDirectory;
^
./lucene_test/IndexFiles.java:52: error: cannot find symbol
private IndexWriter _writer;
^
symbol: class IndexWriter
location: class IndexFiles
./lucene_test/IndexFiles.java:73: error: cannot find symbol
Directory dir = FSDirectory.open(_indexPathObj);
^
symbol: class Directory
location: class IndexFiles
./lucene_test/IndexFiles.java:73: error: cannot find symbol
Directory dir = FSDirectory.open(_indexPathObj);
^
symbol: variable FSDirectory
location: class IndexFiles
./lucene_test/IndexFiles.java:74: error: cannot find symbol
Analyzer analyzer = new StandardAnalyzer();
^
symbol: class Analyzer
location: class IndexFiles
./lucene_test/IndexFiles.java:74: error: cannot find symbol
Analyzer analyzer = new StandardAnalyzer();
^
symbol: class StandardAnalyzer
location: class IndexFiles
./lucene_test/IndexFiles.java:75: error: cannot find symbol
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
^
symbol: class IndexWriterConfig
location: class IndexFiles
./lucene_test/IndexFiles.java:75: error: cannot find symbol
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
^
symbol: class IndexWriterConfig
location: class IndexFiles
./lucene_test/IndexFiles.java:76: error: cannot find symbol
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
^
symbol: variable OpenMode
location: class IndexFiles
./lucene_test/IndexFiles.java:77: error: cannot find symbol
_writer = new IndexWriter(dir, iwc);
^
symbol: class IndexWriter
location: class IndexFiles
./lucene_test/IndexFiles.java:161: error: cannot find symbol
Document doc = new Document();
^
symbol: class Document
location: class IndexFiles
./lucene_test/IndexFiles.java:161: error: cannot find symbol
Document doc = new Document();
^
symbol: class Document
location: class IndexFiles
./lucene_test/IndexFiles.java:164: error: cannot find symbol
doc.add(new TextField("category", category, Field.Store.YES));
^
symbol: class TextField
location: class IndexFiles
./lucene_test/IndexFiles.java:164: error: package Field does not exist
doc.add(new TextField("category", category, Field.Store.YES));
^
./lucene_test/IndexFiles.java:165: error: cannot find symbol
doc.add(new StringField("subject", subject, Field.Store.YES));
^
symbol: class StringField
location: class IndexFiles
./lucene_test/IndexFiles.java:165: error: package Field does not exist
doc.add(new StringField("subject", subject, Field.Store.YES));
^
./lucene_test/IndexFiles.java:175: error: cannot find symbol
doc.add(new LongField("modified", lastModified, Field.Store.NO));
^
symbol: class LongField
location: class IndexFiles
./lucene_test/IndexFiles.java:175: error: package Field does not exist
doc.add(new LongField("modified", lastModified, Field.Store.NO));
^
./lucene_test/IndexFiles.java:181: error: cannot find symbol
doc.add(new TextField("contents", new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))));
^
symbol: class TextField
location: class IndexFiles
./lucene_test/IndexFiles.java:184: error: cannot find symbol
if (_writer.getConfig().getOpenMode() == OpenMode.CREATE)
^
symbol: variable OpenMode
location: class IndexFiles
./lucene_test/IndexFiles.java:195: error: cannot find symbol
_writer.updateDocument(new Term("path", file.toString()), doc);
^
symbol: class Term
location: class IndexFiles

更新:

因为我是在 Linux 操作系统上编译的,所以 classpath 中的多个目录应该用冒号 (:) 而不是分号 (;) 分隔。所以这是新的复杂代码,我也包含了 jar 文件的完整路径,但它仍然找不到那些 jar 文件中定义的类。

javac -classpath ~/search_example/lucene-5.0.0/analysis/common/lucene-analyzers-common-5.0.0.jar:~/search_example/lucene-5.0.0/core/lucene-core-5.0.0.jar:~/search_example/lucene-5.0.0/queries/lucene-queries-5.0.0.jar:~/search_example/lucene-5.0.0/queryparser/lucene-queryparser-5.0.0.jar lucene_test/*.java 

最佳答案

提供类路径变量的完整路径或至少从当前目录中正确引用总是好的。

但是,使用像 maven 这样的构建工具总是好的,它有助于绕过依赖项和类路径。

关于java - 从命令行错误在 Linux 上编译 Java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29350868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com