Java 关于 Eclipse 中 lib 文件夹的一个简单问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4410803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 17:10:35  来源:igfitidea点击:

a simple question about lib folder in Eclipse

javaeclipse

提问by Kevin

I am new to Eclipse IDE, I created a new project named "Hello World", and I need some APIs which are contained in a jar file.

我是 Eclipse IDE 的新手,我创建了一个名为“Hello World”的新项目,我需要一些包含在 jar 文件中的 API。

I created a folder called "lib" under the project folder "Hello World" (parallel with src folder), and I import the .jar file into this lib folder, it extracts all the things to this lib folder automatically.

我在项目文件夹“Hello World”(与 src 文件夹并行)下创建了一个名为“lib”的文件夹,并将 .jar 文件导入到这个 lib 文件夹中,它会自动将所有内容提取到这个 lib 文件夹中。

Then I created my HelloWorld.java class under src folder, however, when I put import ro.xxx.xxx.xxx, eclipse complains "the import ro cannot be resolved". Actually, the ro is under the lib folder.

然后我在 src 文件夹下创建了我的 HelloWorld.java 类,但是,当我输入 import ro.xxx.xxx.xxx 时,eclipse 抱怨“无法解析导入 ro”。实际上,ro 在 lib 文件夹下。

I am stuck here. Shall I make this lib folder under the src folder instead of parallel with it? Please kindly give me some suggestions, thanks in advance!

我被困在这里。我应该将这个 lib 文件夹放在 src 文件夹下而不是与之平行吗?请给我一些建议,在此先感谢!

采纳答案by Stan Kurilin

Project -> properties -> Java build path -> libraries -> add external jars

项目 -> 属性 -> Java 构建路径 -> 库 -> 添加外部 jar

回答by Jigar Joshi

Just Putting jar in lib folder won't work, you need those jars in your class path.

只是将 jar 放在 lib 文件夹中是行不通的,您需要在类路径中使用这些 jar。

Here it is described how to add jars in to your build path in eclipse

这里描述了如何在eclipse中将jars添加到你的构建路径中

回答by Mark Baijens

Add the library to your build path.

将库添加到您的构建路径。

Right mouse button on your project --> Build Path --> Configure Build Path...

在您的项目上单击鼠标右键 --> 构建路径 --> 配置构建路径...

Libraries --> Add jar

库 --> 添加 jar

回答by Squidious

After you first create the lib folder parallel to the src folder you need to go back into Eclipse and Refreshthe project so that Eclipse finds the new folder and jars. You can either highlight the project and hit F5, or use the right click menu off the project. After that the lib folder and jar files appear and you can right click a jar to add to the build path. If you add new jars subsequently you need to refresh again for Eclipse to find them.

在您首先创建与 src 文件夹平行的 lib 文件夹后,您需要返回 Eclipse 并刷新项目,以便Eclipse 找到新文件夹和 jars。您可以突出显示项目并按 F5,也可以使用项目外的右键单击菜单。之后 lib 文件夹和 jar 文件出现,您可以右键单击一个 jar 以添加到构建路径。如果随后添加新 jar,则需要再次刷新,以便 Eclipse 找到它们。