在 Java 中导入 API (eclipse)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10970484/
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
Importing an API in Java (eclipse)
提问by timsbleung
I'm trying to import an API that I found online - joda time - into my program.
我正在尝试将我在网上找到的 API - joda time - 导入到我的程序中。
I've downloaded the files, stuck them in my source folder, but obviously since it isn't integrated into my program they won't work.
我已经下载了这些文件,将它们放在我的源文件夹中,但显然由于它没有集成到我的程序中,因此它们将无法工作。
I've spent a lot of time googling around for different methods (maybe I'm searching for the wrong thing?) as well as just randomly doing a bunch of different things inside eclipse (I'm developing with eclipse) that include the word "package" or "import", to no avail.
我花了很多时间在谷歌上搜索不同的方法(也许我在寻找错误的东西?)以及在 eclipse 中随机做一堆不同的事情(我正在用 eclipse 开发),其中包括这个词“包”或“导入”,无济于事。
I don't know if it's worth mentioning but my program is being built with the google app engine, and all their stuff is organized in a nice com.xxx.xxxx format, which I think is ultimately what I need to get my stuff into - I just don't know how.
我不知道是否值得一提,但我的程序是用谷歌应用引擎构建的,他们所有的东西都以一个很好的 com.xxx.xxxx 格式组织,我认为这最终是我需要把我的东西放进去的- 我只是不知道怎么做。
Anyway, sorry if this is a ridiculously trivial question, and thanks in advance to anyone that helps.
无论如何,对不起,如果这是一个可笑的微不足道的问题,并提前感谢任何有帮助的人。
回答by JB Nizet
You should just have to put the joda-time jar file inside the WEB-INF/lib folder of your project. This folder contains all the libraries that must be delivered with your application, and are automatically added to the build path of your project by Eclipse.
您应该只需要将 joda-time jar 文件放在项目的 WEB-INF/lib 文件夹中。该文件夹包含必须与应用程序一起交付的所有库,Eclipse 会自动将其添加到项目的构建路径中。
回答by Jonathan B
Since you are using Eclipse, you can use the library functions to add in external packages.
由于您使用的是 Eclipse,您可以使用库函数添加外部包。
- Right click on your project, and then choose Build Path--> Configure Build Path.
- Click on the Librariesbutton at the top, and then click the Add External JARs...button.
- Select the JAR file in your JODA directory.
- 右键单击您的项目,然后选择Build Path--> Configure Build Path。
- 单击顶部的Libraries按钮,然后单击Add External JARs...按钮。
- 在 JODA 目录中选择 JAR 文件。
If you are using the Eclipse deployment tools, this will automatically package your JAR file in to your web application. If it doesn't do that automatically, add that same JAR file in to your WEB-INF/lib directory (copy it in to your project).
如果您使用 Eclipse 部署工具,这将自动将您的 JAR 文件打包到您的 Web 应用程序中。如果它没有自动执行此操作,请将相同的 JAR 文件添加到您的 WEB-INF/lib 目录中(将其复制到您的项目中)。