怎样把一个jar包导入到Eclipse的一个工程中?
1‘在workspace中点中你要加入包的工程;
2’工具栏project——Properties;
3‘选中左侧栏里的Java Build Path,然后选择Libraries选项卡;
4’点击右侧的‘Add External Jars’,选择你导入的包,打开,OK就可以了。
但是这样建立的jar包在那个文件夹呢?workspace文件夹里没有啊。
9 个解决方案
#1
http://jingyan.baidu.com/article/ca41422fc76c4a1eae99ed9f.html
上面的链接有关于如何在lib文件夹中存放从外部引入的jar包的介绍,在其步骤3中提到:
此时,打开选择框,我们选择默认的【copy files】,点击【OK】关闭。然后我们就可以在lib文件夹下看到我们复制成功的jar包。
但是不知“选择框”指那个,“默认的【copy files】”在那里?
上面的链接有关于如何在lib文件夹中存放从外部引入的jar包的介绍,在其步骤3中提到:
此时,打开选择框,我们选择默认的【copy files】,点击【OK】关闭。然后我们就可以在lib文件夹下看到我们复制成功的jar包。
但是不知“选择框”指那个,“默认的【copy files】”在那里?
#2
工程目录下面有
项目名称\WebRoot\WEB-INF\lib
项目名称\WebRoot\WEB-INF\lib
#3
你是添加额外的,你的jar包原来在哪还再哪,它不会帮你复制到workspace中
#4
程序运行不了,不知这样是不是已经向工程中导入了jar包?
#5
你导入下jar包里面的类就知道是不是导进来了。。
= =不出意外应该没错了
#6
导入下jar包里面的类?用快捷键Ctrl+Shift+O自动导包?
#7
贴一下程序出错的代码
#8
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
QueryParser cannot be resolved to a type
DirectoryReader cannot be resolved
Type mismatch: cannot convert from org.apache.lucene.document.Document to javax.swing.text.Document
The method get(String) is undefined for the type Document
The method get(String) is undefined for the type Document
at HelloLucene.main(HelloLucene.java:44)
import org.apache.lucene.queryParser.QueryParser;
在Eclipse中显示:
The import org.apache.lucene.queryParser cannot be resolved
在Eclipse中显示:
已经在项目中导入了lucene-queryparser-4.0.0.jar
QueryParser cannot be resolved to a type
DirectoryReader cannot be resolved
Type mismatch: cannot convert from org.apache.lucene.document.Document to javax.swing.text.Document
The method get(String) is undefined for the type Document
The method get(String) is undefined for the type Document
at HelloLucene.main(HelloLucene.java:44)
import org.apache.lucene.queryParser.QueryParser;
在Eclipse中显示:
The import org.apache.lucene.queryParser cannot be resolved
在Eclipse中显示:
已经在项目中导入了lucene-queryparser-4.0.0.jar
#9
源代码如下:
import java.awt.TextField;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.ParseException;
import javax.swing.text.Document;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
public class HelloLucene {
public static void main(String[] args) throws IOException, ParseException {
// 0. Specify the analyzer for tokenizing text.
// The same analyzer should be used for indexing and searching
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
// 1. create the index
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Lucene in Action", "193398817");
addDoc(w, "Lucene for Dummies", "55320055Z");
addDoc(w, "Managing Gigabytes", "55063554A");
addDoc(w, "The Art of Computer Science", "9900333X");
w.close();
// 2. query
String querystr = args.length > 0 ? args[0] : "lucene";
// the "title" arg specifies the default field to use
// when no field is explicitly specified in the query.
Query q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);
// 3. search
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
// 4. display results
System.out.println("Found " + hits.length + " hits.");
for(int i=0;i<hits.length;++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("isbn") + "\t" + d.get("title"));
}
// reader can only be closed when there
// is no need to access the documents any more.
reader.close();
}
private static void addDoc(IndexWriter w, String title, String isbn) throws IOException {
Document doc = new Document();
doc.add(new TextField("title", title, Field.Store.YES));
// use a string field for isbn because we don't want it tokenized
doc.add(new StringField("isbn", isbn, Field.Store.YES));
w.addDocument(doc);
}
}
import java.awt.TextField;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.ParseException;
import javax.swing.text.Document;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
public class HelloLucene {
public static void main(String[] args) throws IOException, ParseException {
// 0. Specify the analyzer for tokenizing text.
// The same analyzer should be used for indexing and searching
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
// 1. create the index
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Lucene in Action", "193398817");
addDoc(w, "Lucene for Dummies", "55320055Z");
addDoc(w, "Managing Gigabytes", "55063554A");
addDoc(w, "The Art of Computer Science", "9900333X");
w.close();
// 2. query
String querystr = args.length > 0 ? args[0] : "lucene";
// the "title" arg specifies the default field to use
// when no field is explicitly specified in the query.
Query q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);
// 3. search
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
// 4. display results
System.out.println("Found " + hits.length + " hits.");
for(int i=0;i<hits.length;++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("isbn") + "\t" + d.get("title"));
}
// reader can only be closed when there
// is no need to access the documents any more.
reader.close();
}
private static void addDoc(IndexWriter w, String title, String isbn) throws IOException {
Document doc = new Document();
doc.add(new TextField("title", title, Field.Store.YES));
// use a string field for isbn because we don't want it tokenized
doc.add(new StringField("isbn", isbn, Field.Store.YES));
w.addDocument(doc);
}
}
#1
http://jingyan.baidu.com/article/ca41422fc76c4a1eae99ed9f.html
上面的链接有关于如何在lib文件夹中存放从外部引入的jar包的介绍,在其步骤3中提到:
此时,打开选择框,我们选择默认的【copy files】,点击【OK】关闭。然后我们就可以在lib文件夹下看到我们复制成功的jar包。
但是不知“选择框”指那个,“默认的【copy files】”在那里?
上面的链接有关于如何在lib文件夹中存放从外部引入的jar包的介绍,在其步骤3中提到:
此时,打开选择框,我们选择默认的【copy files】,点击【OK】关闭。然后我们就可以在lib文件夹下看到我们复制成功的jar包。
但是不知“选择框”指那个,“默认的【copy files】”在那里?
#2
工程目录下面有
项目名称\WebRoot\WEB-INF\lib
项目名称\WebRoot\WEB-INF\lib
#3
你是添加额外的,你的jar包原来在哪还再哪,它不会帮你复制到workspace中
#4
程序运行不了,不知这样是不是已经向工程中导入了jar包?
#5
你导入下jar包里面的类就知道是不是导进来了。。
= =不出意外应该没错了
#6
导入下jar包里面的类?用快捷键Ctrl+Shift+O自动导包?
#7
贴一下程序出错的代码
#8
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
QueryParser cannot be resolved to a type
DirectoryReader cannot be resolved
Type mismatch: cannot convert from org.apache.lucene.document.Document to javax.swing.text.Document
The method get(String) is undefined for the type Document
The method get(String) is undefined for the type Document
at HelloLucene.main(HelloLucene.java:44)
import org.apache.lucene.queryParser.QueryParser;
在Eclipse中显示:
The import org.apache.lucene.queryParser cannot be resolved
在Eclipse中显示:
已经在项目中导入了lucene-queryparser-4.0.0.jar
QueryParser cannot be resolved to a type
DirectoryReader cannot be resolved
Type mismatch: cannot convert from org.apache.lucene.document.Document to javax.swing.text.Document
The method get(String) is undefined for the type Document
The method get(String) is undefined for the type Document
at HelloLucene.main(HelloLucene.java:44)
import org.apache.lucene.queryParser.QueryParser;
在Eclipse中显示:
The import org.apache.lucene.queryParser cannot be resolved
在Eclipse中显示:
已经在项目中导入了lucene-queryparser-4.0.0.jar
#9
源代码如下:
import java.awt.TextField;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.ParseException;
import javax.swing.text.Document;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
public class HelloLucene {
public static void main(String[] args) throws IOException, ParseException {
// 0. Specify the analyzer for tokenizing text.
// The same analyzer should be used for indexing and searching
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
// 1. create the index
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Lucene in Action", "193398817");
addDoc(w, "Lucene for Dummies", "55320055Z");
addDoc(w, "Managing Gigabytes", "55063554A");
addDoc(w, "The Art of Computer Science", "9900333X");
w.close();
// 2. query
String querystr = args.length > 0 ? args[0] : "lucene";
// the "title" arg specifies the default field to use
// when no field is explicitly specified in the query.
Query q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);
// 3. search
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
// 4. display results
System.out.println("Found " + hits.length + " hits.");
for(int i=0;i<hits.length;++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("isbn") + "\t" + d.get("title"));
}
// reader can only be closed when there
// is no need to access the documents any more.
reader.close();
}
private static void addDoc(IndexWriter w, String title, String isbn) throws IOException {
Document doc = new Document();
doc.add(new TextField("title", title, Field.Store.YES));
// use a string field for isbn because we don't want it tokenized
doc.add(new StringField("isbn", isbn, Field.Store.YES));
w.addDocument(doc);
}
}
import java.awt.TextField;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.ParseException;
import javax.swing.text.Document;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
public class HelloLucene {
public static void main(String[] args) throws IOException, ParseException {
// 0. Specify the analyzer for tokenizing text.
// The same analyzer should be used for indexing and searching
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
// 1. create the index
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Lucene in Action", "193398817");
addDoc(w, "Lucene for Dummies", "55320055Z");
addDoc(w, "Managing Gigabytes", "55063554A");
addDoc(w, "The Art of Computer Science", "9900333X");
w.close();
// 2. query
String querystr = args.length > 0 ? args[0] : "lucene";
// the "title" arg specifies the default field to use
// when no field is explicitly specified in the query.
Query q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);
// 3. search
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
// 4. display results
System.out.println("Found " + hits.length + " hits.");
for(int i=0;i<hits.length;++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("isbn") + "\t" + d.get("title"));
}
// reader can only be closed when there
// is no need to access the documents any more.
reader.close();
}
private static void addDoc(IndexWriter w, String title, String isbn) throws IOException {
Document doc = new Document();
doc.add(new TextField("title", title, Field.Store.YES));
// use a string field for isbn because we don't want it tokenized
doc.add(new StringField("isbn", isbn, Field.Store.YES));
w.addDocument(doc);
}
}