Eclipse、Java:如何以 zip 格式导入库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14375810/
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, Java: How to import a library in zip-format?
提问by AlexR
Ok, this is basic, but it seems that the normal way of doing this doesn't work for me.
好的,这是基本的,但似乎这样做的正常方法对我不起作用。
I'm trying to import the jSSC library, for communication with serial ports etc. The newest library is jSSC-0.9.0-Release
我正在尝试导入 jSSC 库,用于与串行端口等通信。最新的库是 jSSC-0.9.0-Release
So, I've tried the following:
所以,我尝试了以下方法:
- Placed the zip file in the workspace and added it as "external jar" in the project properties -> java build path -> libraries.
- 将 zip 文件放在工作区中,并在项目属性 -> java 构建路径 -> 库中将其添加为“外部 jar”。
Then I try including something from the library:
然后我尝试包含库中的内容:
import jssc.SerialPortList;
Error: The import jssc cannot be resolved
错误:无法解析导入jssc
- Then I placed the zip file in a folder called /libs in the project root, and added it as "jar" (not external).
- 然后我将 zip 文件放在项目根目录中名为 /libs 的文件夹中,并将其添加为“jar”(不是外部的)。
Result: Same error.
结果:同样的错误。
What basic info/action am I missing here, for this simple operation of importing a library?
对于导入库的简单操作,我在这里缺少哪些基本信息/操作?
回答by Bastien Jansen
Are you sure you should include the zip directly? In most releases, the zip contain a jar + readme + some documentation. I think you should take a look at the content of this zip file, perhaps extract it and only include the jar in your project.
您确定应该直接包含 zip 吗?在大多数版本中,zip 包含一个 jar + 自述文件 + 一些文档。我认为你应该看看这个 zip 文件的内容,也许解压缩它并且只在你的项目中包含 jar。
回答by AlexR
I believe that your zip file contains a lot of files including jar file with all classes you need, documentation etc. So, extract zip file, find jar you have to add to your eclipse project and do that.
我相信您的 zip 文件包含很多文件,包括带有您需要的所有类的 jar 文件、文档等。因此,解压缩 zip 文件,找到您必须添加到 eclipse 项目中的 jar 并执行此操作。
The zip probably contains readme instructions. Read them. This will probably help you to install and use the library.
zip 可能包含自述文件说明。阅读它们。这可能会帮助您安装和使用该库。