博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Eclipse中导入外部jar包
阅读量:5758 次
发布时间:2019-06-18

本文共 3660 字,大约阅读时间需要 12 分钟。

Eclipse中导入外部jar包

  • 在编写java代码时,为方便编程,常常会引用别人已经实现的方法,通常会封装成jar包,我们在编写时,只需引入到Eclipse中即可。

工具/原料

  • Eclipse

  • 需要引入的jar包

方法/步骤

  1. 1

    首先在项目下创建一个文件夹,保存我们的jar包。

    在项目名上右击,依次点击【New】-->【Floder】,打开新建文件夹窗口

  2. 2

    输入文件夹名称【lib】,点击【ok】。我们通常在lib文件夹中存放从外部引入的jar包

  3. 3

    找到我们要引入的jar包,鼠标选中jar包,然后按住鼠标左键不放,把jar包拖到lib文件夹中。或先复制jar包,然后在lib文件夹上右击,选择复制。此时,打开选择框,我们选择默认的【copy files】,点击【OK】关闭。然后我们就可以在lib文件夹下看到我们复制成功的jar包。

  4. 4

    此时,只是把jar包复制到项目中,还不能使用。我们再在项目名上右击,依次选择

    【Build Path】-->【Configure Build Path...】。

  5. 5

    在打开的窗口中,先选中【Libraries】页,再从右边的按钮中点击

    【add JARs...】

  6. 6

    在打开的窗口中,我们依次展开本项目的项目和lib文件夹,然后选中我们刚才复制到项目中的jar包,然后点击【OK】关闭窗口

  7. 7

    此时,我们在刚才打开的【Libraries】页中可以看到我们引入的jar包的名称。点击【OK】确认。

  8. 8

    此时,在Eclipse中,我们就可以使用这个jar包了。

    END

注意事项

  • 当我们不需要该jar包时,只需按相反的顺序即可删除该jar包。

 

eclipse教程:

25. Using JARs (libraries) in Eclipse

25.1. Adding a Java library to the project classpath

If the libraries should be distributed with your project, you can store the JAR files directly in your project.

For example, you can create a new Java project de.vogella.eclipse.ide.jars. Then create a new folder called lib by right-clicking on your project and selecting New → Folder.

Creating a new folder

From the menu select File → Import → General → File System. Select the Java library you want to import and select the lib folder as target. Alternatively, just copy and paste the jar file into the lib folder.

You can add this library to your classpath, right-click on the JAR file and select Build Path → Add to Build Path.

To manage your classpath, right-click on your project and select Properties. Under Java Build Path → Libraries select the Add JARs button.

The following example shows how the result would look like if the junit-4.4.jar file had been added to the project.

Adding a jar to the current project

After adding it to the classpath, Eclipse allows you to use the classes contained in the JAR file in the project . Outside Eclipse you still need to configure your classpath, e.g., via the MANIFEST.MF file.

25.2. Attach source code to a Java library

You can open any class by positioning the cursor on the class in an editor and pressing F3. Alternatively, you can pressCtrl+Shift+T. This will show a dialog in which you can enter the class name to open it.

If the source code is not available, the editor will show the bytecode of that class.

This happens, for example, if you open a class from a the standard Java library without attaching the source code to it.

To see the source code of such a class, you can attach a source archive or source folder to a Java library. Afterwards, the editor shows the source instead of the bytecode.

Attaching the source code to a library also allows you to debug this source code.

The Source Attachment dialog can be reached in the Java Build Path page of a project. To open this page, right-click on a project and select Properties → Java Build Path. On the Libraries tab, expand the library's node, select the Source Attachment attribute and click the Edit button.

In the Location path field, enter the path of an archive or a folder containing the source.

The following screenshot shows this setting for the standard Java library. If you have the Java Development Kit (JDK) installed, you should find the source in the JDK installation folder. The file is typically called src.zip.

Maintaining the location of the source attachment to an jar

25.3. Add Javadoc for a JAR

It is also possible to add Javadoc to a library which you use.

Download the Javadoc of the JAR file and put it somewhere in your filesystem.

To enter the location of the Javadoc, open the Java Build Path via a right-click on a project and select Properties → Java Build Path. On the Libraries tab expand the library's node, select the Javadoc location attribute and press the Edit button.

Enter the location to the file which contains the Javadoc.

Enter the location to the Javadoc file for a jar file

转载地址:http://zgpkx.baihongyu.com/

你可能感兴趣的文章
jSearch(聚搜) 1.0.0 终于来了
查看>>
Java字节码结构剖析二:字段表
查看>>
盘点2018云计算市场,变化大于需求?
查看>>
极光推送(一)集成
查看>>
Android项目实战(三十九):Android集成Unity3D项目(图文详解)
查看>>
MySQL 8.0 压缩包版安装方法
查看>>
TensorFlow系列专题(六):实战项目Mnist手写数据集识别
查看>>
JS中this的4种绑定规则
查看>>
Netty Pipeline源码分析(2)
查看>>
@Transient注解输出空间位置属性
查看>>
Ansible-playbook 条件判断when、pause(学习笔记二十三)
查看>>
开发者报 | Github造假产业链曝光,花钱就能买Star;黑客又多一个可以偷你密码的方法了...
查看>>
git 相关开发常用
查看>>
编码服务正在步入云端
查看>>
我的友情链接
查看>>
mysql备份
查看>>
数组合并
查看>>
Linux学习笔记--Linux文件管理类命令详解
查看>>
进程间的通信方式
查看>>
数据库连接池(更新中)
查看>>