Eclipse的Library是什么?
Library的翻译是文库,图书馆。在Eclispe中指的是jar档的分组集合。
在Eclispe中,经常使用的Library类型包括:
-
JRE System Library ,Java运行环境相关的包,主要包括Java的基础类。在Eclipse 显示如下:
-
Maven Managed Dependencies, Maven 管理相关的依赖库。
-
User Library: 用户自定义的库,比如JPA开发的Eclipse Link。
将一个或多个关联的jar 包归类在一起,相当于一个包里面包含多个jar 文件, 这样在Eclipse项目中就可以快速使用了。
Library除了分类jar 方便外, 在Eclipse IDE开发中,可以在库中直接展开到jar 一级包含的类文件。
什么是User Library
用户库就是用户自定义的库。定义方式是
Window > Preferences
定位到 Java >Build Path > User Libraries
点击New… 按钮,输入库的名字,保存库。
选中创建的库, 点击Add JARs… 和 Add External JARs… 。增加需要放入该库的jar档。
- Add JARs…, 从Eclipse项目中选择jar
- Add External JARs… , 从外部文件目录选择jar
深度解密
在项目中引入库之后, Eclipse 是如何处理的呢?
项目中引用库之后, 在.classpath 中会增加以下配置:
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/eclipselink">
<attributes>
<attribute name="owner.project.facets" value="jpt.jpa"/>
</attributes>
</classpathentry>
而这个库的定义的位置是:
%workspace%.metadata.plugins\org.eclipse.core.runtime.settings\org.eclipse.jdt.core.prefs