将 zip 文件作为库导入 - Eclipse Java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17373997/
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-09-19 20:48:57  来源:igfitidea点击:

Importing zip file as library - Eclipse Java

javaeclipsejarimportgoogle-api-java-client

提问by Victor R. Oliveira

I stucked here importing google http library. I made some research in links such as:

我坚持在这里导入谷歌 http 库。我对链接进行了一些研究,例如:

  1. Eclipse, Java: How to import a library in zip-format?
  2. Import Libraries in Eclipse?
  1. Eclipse、Java:如何以 zip 格式导入库?
  2. 在 Eclipse 中导入库?

The thing is, I imported correctly and was working right. But after some point it stopped to work. I creater one user library, imported the zip file which contain the library but it's not sort of "compiling the library".

问题是,我正确导入并且工作正常。但过了一段时间它停止工作。我创建了一个用户库,导入了包含该库的 zip 文件,但它不是“编译库”。

Take a look at the print, please:enter image description here

看看印刷品,请:在此处输入图片说明

I'm trying to solve on my own for four hours but I'm getting tired... could anyone help me please?

我试图自己解决四个小时,但我很累……有人可以帮我吗?

Edit One:

编辑一:

enter image description here

在此处输入图片说明

Edit Two:

编辑二:

enter image description here

在此处输入图片说明

采纳答案by Victor R. Oliveira

Did some more research and found this:

做了一些更多的研究,发现了这一点:

  1. How to add external library properly in Eclipse?
  1. 如何在 Eclipse 中正确添加外部库?

I then followed the steps:

然后我按照以下步骤操作:

  1. Extracted all google api content to one folder named lib
  2. Created a New User Librarby Window -> Preference -> Java -> Build Path -> New -> Name your library -> left the System Library unchecked -> Add External Jars -> manually added the needed jars.
  3. Right click on project folder -> Build Path -> Configure Build Path -> Libraries -> Add Library -> User Library -> checked the created user library.
  1. 将所有 google api 内容提取到一个名为 lib 的文件夹中
  2. 创建一个新的用户库通过窗口 -> 首选项 -> Java -> 构建路径 -> 新建 -> 命名你的库 -> 不选中系统库 -> 添加外部罐子 -> 手动添加所需的罐子。
  3. 右键单击项目文件夹-> 构建路径-> 配置构建路径-> 库-> 添加库-> 用户库-> 选中创建的用户库。

In conclusion: Don't ever import the library as a zip or you will have a long headache.

结论:永远不要将库作为 zip 导入,否则您会很头疼。

Hope this helps someone else.

希望这对其他人有帮助。

Edit: In case of some error showing up, like missing files belonging to the user library, cleaning the project may prove to be a solution. However, refreshing the project worked just fine for me. Try pressing F5 or right clicking on your project folder and select refresh.

编辑:如果出现一些错误,例如丢失属于用户库的文件,清理项目可能是一个解决方案。但是,刷新项目对我来说效果很好。尝试按 F5 或右键单击您的项目文件夹并选择刷新。

回答by Dan Da Man

Seems like there is a shortcoming of Eclipse not being able to extract .jar files from .zip files (which is the form of many "combo" library packages out there). I wonder if there is a plugin or some other, easier way of directly adding .zip file to java projects via command line or some other way.

Eclipse 似乎有一个缺点,即无法从 .zip 文件中提取 .jar 文件(这是许多“组合”库包的形式)。我想知道是否有插件或其他更简单的方法可以通过命令行或其他方式将 .zip 文件直接添加到 java 项目。

回答by Tom G

Right click on you class that you want to use the library in on the left hand panel in eclipse. Select "Build Path" => "Configure Build Path".

在 eclipse 的左侧面板上,右键单击要在其中使用库的类。选择“构建路径”=>“配置构建路径”。

Click on the Libraries tab

单击库选项卡

Click on the "Add External Jars" button

单击“添加外部罐子”按钮

Browse your file system for any .jar files(Java archives) that you want to include in your build path.

浏览文件系统以查找要包含在构建路径中的任何 .jar 文件(Java 档案)。

There you go.. you should now be able to use the archived classes in you code

你去吧..你现在应该能够在你的代码中使用存档的类