简体   繁体   English

Eclipse IDE-添加jar?添加外部jar?添加图书馆?

[英]Eclipse IDE- Add jar? Add External jar? Add Library?

I want to integrate TwitterAPIME to my Blackberry project. 我想将TwitterAPIME集成到我的Blackberry项目中。 I have 3 Jar files provided by TwitterAPIME . 我有TwitterAPIME提供的3个Jar文件。 I am not sure how to link these 3 Jar files to my project. 我不知道如何将这3个Jar文件链接到我的项目。

My basic doubts are 我的基本疑虑是

What is an External Jar ? 什么是外部罐子? What is a Library ? 什么是图书馆?

What's the difference between Adding jar, Adding External jar or Adding Library ? 添加jar,添加外部jar或添加库有什么区别?

What is an External JAR? 什么是外部JAR?

  • External as the name suggest is a Jar file that is not built by the currently developing code. 顾名思义外部是一个Jar文件,它不是由当前正在开发的代码构建的。 It is a utility Jar file that is added externally for extra features. 它是一个实用工具Jar文件,外部添加了额外的功能。 It could be an API Jar file provided from the external site, just as in your case the 3 Jar files will be going to call External Jar Files. 它可以是从外部站点提供的API Jar文件,就像你的情况一样,3 Jar文件将调用外部Jar文件。
  • To add an External Jar file in Eclipse, follow these steps: Right Click on Project -> Select Build Path -> Select Configure Build Path -> Library Tab in the following Dialog box. 要在Eclipse中添加外部Jar文件,请按照下列步骤操作:在下面的对话框中右键单击项目 - >选择构建路径 - >选择配置构建路径 - >库选项卡。

What is a Library? 什么是图书馆?

A Library is a in-built Jar file from the JDK Directory or any other software eg J2ME-Polish as you can see in the Image above. 库是JDK目录中的内置Jar文件或任何其他软件,例如J2ME-Polish,如上图所示。 Normally these Library files are developed by a manufacturer. 通常,这些库文件是由制造商开发的。

What's the difference between adding JAR, Adding External JAR, and Adding Library? 添加JAR,添加外部JAR和添加库有什么区别?

  • Adding Jar File: When you have more than one project in Eclipse and you add another project's Jar file, that is called adding Jar File. 添加Jar文件:当你在Eclipse中有多个项目并添加另一个项目的Jar文件时,这称为添加Jar文件。 There is a first Button in the Photo above, it only allows you to add Jar file from the other Project. 上面的照片中有第一个按钮,它只允许您从其他项目添加Jar文件。
  • Adding External Jar: When you add any API Jar file provided by the site or another manufacturer. 添加外部Jar:添加站点或其他制造商提供的任何API Jar文件时。 In your case the 3 Jar files are External Jar Files. 在您的情况下,3 Jar文件是外部Jar文件。 You can add then by using second Button "Add External JARs". 您可以使用第二个按钮“添加外部JAR”添加。
  • Adding A Library: Clicking on the 4th Button will open a dialog box as below. 添加库:单击第4个按钮将打开如下对话框。

    You can add different libraries installed on your system. 您可以添加系统上安装的不同库。 You can also add your own Library, by selecting "User Library". 您也可以通过选择“用户库”添加自己的库。

JAR: A JAR File in your workspace. JAR:工作空间中的JAR文件。

External JAR: A JAR File in your file system. 外部JAR:文件系统中的JAR文件。 Use it for test purposes only, otherwise your project would be quite untidy. 仅用于测试目的,否则您的项目将非常不整洁。

Library: Built-in libraries such as JUnit. 库:内置库,如JUnit。 You don't need to know their location, these come with Eclipse. 您不需要知道它们的位置,这些都来自Eclipse。

In addition to the excellent answer given above by Lucifer, I recommend that people looking to develop or use Libraries, review the following BB supplied KB article: 除了Lucifer上面给出的优秀答案之外,我建议那些希望开发或使用Libraries的人,查看以下BB提供的知识库文章:

Working with Libraries - shared, bundled, releasing, and using 3rd Party SDKs 使用库 - 共享,捆绑,发布和使用第三方SDK

Where the API is available as source or a Jar, I have found it significantly easier to include the source directly in the application. 如果API可用作源或Jar,我发现将源直接包含在应用程序中要容易得多。 For example, in this case, rather than include the TwitterAPIME jar, you could include the TwitterAPIME source as a separate project in the application. 例如,在这种情况下,您可以将TwitterAPIME源包含在应用程序中作为单独的项目,而不是包含TwitterAPIME jar。 As well as being easier to build, this can help in debugging or at least understanding issues with the API. 除了更容易构建之外,这还有助于调试或至少了解API的问题。

You might also find this sample, and in fact the containing Thread, useful: 您可能还会发现此示例,实际上包含Thread,非常有用:

Twitter + Facebook Sample Integration Twitter + Facebook样本整合

Also building on Lucifer's answer, I have used "User Libraries" to bundle jars that are used across projects and dependent on a 3rd party service. 同样基于路西法的答案,我使用“用户库”来捆绑跨项目使用并依赖于第三方服务的罐子。 Specifically, in my case, JMS jars. 具体来说,就我而言,JMS罐子。 If I upgrade to a new JMS, or a different provider, etc, I can simply change the jars in my User Library and all projects referencing this are updated. 如果我升级到新的JMS或其他提供商等,我只需更改用户库中的jar,并更新引用它的所有项目。 Rather than changing jar dependency in every project. 而不是在每个项目中更改jar依赖项。

An external Jar is a Jar in a path outh of your Eclipse environment: ie outside of both Eclipse jars and projects generated jars. 外部Jar是Eclipse环境中的一个Jar:即在Eclipse jar和项目生成的jar之外。

A libraray is a collection of jars prepared by someone for you. 图书馆是由某人为您准备的罐子集合。

You can cerate a User Library by selecting a group of external jars: that is useful if you have a group o jars that should logically work togehter. 您可以通过选择一组外部jar来终止用户库:如果您有一个逻辑上可以工作的组,那么这将非常有用。 A further advantage of creating a library is that you can "reuse it's definition" by referencing it in multiple projects. 创建库的另一个好处是,您可以通过在多个项目中引用它来“重用它的定义”。

Use: Project->Properties->Add library-> select "User library" and press Next->User libraries->New insert a new name and later us "Add Jar" that adds any jar you need to you library definition. 使用:项目 - >属性 - >添加库 - >选择“用户库”并按下Next->用户库 - >新建一个新名称,然后再添加“添加罐子”,将您需要的任何罐子添加到库定义中。 Later use this library in your project. 稍后在项目中使用此库。

Sometimes adding jars directly in the blackberry project might cause some build problems. 有时直接在blackberry项目中添加jar可能会导致一些构建问题。 Here 'sa solution that works (90%): 这是一个有效的解决方案(90%):

  1. You have your blackberry project. 你有黑莓项目。 Now create a new simple Java Project . 现在创建一个新的简单Java Project
  2. Right-click on it > Properties > Java Build Path and choose Libraries tab and click on Add External Jars to add the 3 jars that are in your system and you want to use. 右键单击它> Properties > Java Build Path并选择Libraries选项卡,然后单击Add External Jars以添加系统中要使用的3个jar。 Then OK . OK
  3. Now go back to your blackberry project and Right-click on it > Properties > Java Build Path and click on the Projects tab, click on Add and select the project you just created and OK. 现在回到你的blackberry项目并右键单击它> Properties > Java Build Path并单击Projects选项卡,单击Add并选择刚创建的Projects ,然后单击OK。
  4. Now go back and build your Blackberry project. 现在回过头来构建你的Blackberry项目。

I hope this help. 我希望这有帮助。

如果在Eclipse工作区中添加JAR,请说/ myproject / WebRoot / WEB-INF / lib但是在使用Select Jar弹出窗口时Eclipse不显示/ lib,退出向导并刷新WebRoot(rtClick并执行Refresh或F5):Eclipse仅显示尚未添加到项目中的新库,通常需要先手动刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM