Eclipse IDE——如何将外部 .jar 文件放入 lib 文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20234589/
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
Eclipse IDE -- how do I put my external .jar files into a lib folder?
提问by RalphF
Eclipse IDE - Can someone please tell me how I can group my external .jar files into a C:\lib folder? I'd really like have them all in a lib folder and not taking up vertical space in the root of my project (see attachment).
Eclipse IDE - 有人可以告诉我如何将外部 .jar 文件分组到 C:\lib 文件夹中吗?我真的很想把它们都放在一个 lib 文件夹中,而不是占用我项目根目录中的垂直空间(见附件)。
I have read some of the similar posts here and tried them but my projects still are not 'seeing' the needed .jar files! It's very frustrating.
我在这里阅读了一些类似的帖子并尝试了它们,但我的项目仍然没有“看到”所需的 .jar 文件!这很令人沮丧。
I know how to add a Folder but how do I tell Eclipse my .jar folders are in c:\lib so my projects will execute? I'm not even sure if making a lib folder in my project is even related to the fact that my jar files happen to be in c:\lib.
我知道如何添加文件夹,但如何告诉 Eclipse 我的 .jar 文件夹在 c:\lib 中,以便我的项目可以执行?我什至不确定在我的项目中创建一个 lib 文件夹是否与我的 jar 文件恰好在 c:\lib 中有关。
Thanks...
谢谢...
(source: msgVault.com)
(来源:msgVault.com)
回答by Dan
From your description it sounds to me like you want the jars to stop taking up space in the root of your project. I am not sure how you initially added them but if I am adding external jars this is what I usually do:
根据您的描述,我觉得您希望 jars 停止占用项目根目录中的空间。我不确定你最初是如何添加它们的,但如果我添加外部罐子,这就是我通常做的:
Right click on your project, select properties, then Java Build Path, and then click the libraries tab, click on add external jars and then you can select each one individually (which would be a pain) or you can select them all at once if they are in the same folder (hence the c:/lib). Click OK and it should add them into a Referenced Libraries folder like so:
右键单击您的项目,选择属性,然后选择 Java 构建路径,然后单击库选项卡,单击添加外部 jar,然后您可以单独选择每个(这会很痛苦)或者您可以一次选择它们,如果它们在同一个文件夹中(因此是 c:/lib)。单击“确定”,它应该将它们添加到“引用库”文件夹中,如下所示:
Also, when you open the libraries tab initially, if all of your jars show there, remove them before proceeding as you don't want to import them twice into your application (If that's even posssible, not sure).
此外,当您最初打开库选项卡时,如果您的所有 jar 都显示在那里,请在继续之前删除它们,因为您不想将它们两次导入到您的应用程序中(如果这甚至可能,不确定)。
Edit
编辑
Switch to Package explorer:
切换到包浏览器:
Click on Window > Show View > Package Explorer
单击窗口 > 显示视图 > 包资源管理器
Update
更新
If you want to add c:\lib
to your project do this:
如果您想添加c:\lib
到您的项目中,请执行以下操作:
Right click on your project, highlight build path, click Add Libraries..., in the list select User Library
, click Next, click User Libraries...
on the right. A new window will open. Click New...
and then give the library a name such as "clibs". Click OK and then highlight the new library and click add external jars. Select the jars you want from c:/lib
and then click OK. Now you can add that User library to any application you want and it will not "pile" up in the root directory under Project View.
右键单击您的项目,突出显示构建路径,单击添加库...,在列表中选择User Library
,单击下一步,单击User Libraries...
右侧。将打开一个新窗口。单击New...
,然后为库命名,例如“clibs”。单击确定,然后突出显示新库并单击添加外部 jar。选择您想要的罐子c:/lib
,然后单击“确定”。现在您可以将该用户库添加到您想要的任何应用程序中,并且它不会“堆积”在项目视图下的根目录中。
回答by Saif Asif
That is just eclipse's way of displaying what libraries are on the build path of the project. It doesn't mean that they are on the root of the project, those are just references to those jars ( that maybe any-where on the system ).
这只是 eclipse 显示项目构建路径上的库的方式。这并不意味着它们位于项目的根目录上,它们只是对那些 jar 的引用(可能在系统上的任何位置)。
A good practice is to get all the jars required by your project and put them in a folder. Next, you can either declare that folder as a library from eclipse and add that library on your build-path or you can just add the jars directly. But they will still be displayed like you are seeing them already. The true path of where these jars are located will be written next to them (like you can see in the attachment C:\selenium....).
一个好的做法是获取项目所需的所有 jar 并将它们放在一个文件夹中。接下来,您可以将该文件夹声明为 Eclipse 中的库并将该库添加到您的构建路径中,或者您可以直接添加 jar。但是它们仍然会像您已经看到的那样显示。这些 jars 所在位置的真实路径将写在它们旁边(就像您在附件 C:\selenium .... 中看到的那样)。