如何在 IntelliJ IDEA 中管理本地类库

一般来说,如果项目是基于 Maven 管理工具的,我们会在 pom.xml 中添加 dependency 来管理依赖。但有时也会遇到要用的类库不在 Maven Repository 的情况。

比较常见的解决方法是把 JARs 安装到 local repository。这种方法的缺点是,只对本机有效,别人拿到你的代码后不能直接使用。这在团队协作中很不方便。

使用 IntelliJ IDEA 的项目设置可以很容易的解决上面的问题。

下面我给大家演示一下。

定义类库

IntelliJ IDEA 支持定义3种级别的类库:

  • global

    对所有项目有效

  • project

    对本项目下所有模块有效

  • module

    仅对本模块有效

我推荐定义 project 级别的类库,然后在 module 中引用。

  1. 在项目根目录下创建lib文件夹,并把jar包复制进去。

    ├─.idea
    ├─lib
    │ taobao-sdk-java-auto_1550480258080-20190218.jar
    └─src
  2. 打开 Project Structure 窗口,选中 Project Settings 下的 Libraries 标签,然后点击右侧的+,选择Java

  3. 在弹出的窗口中选择lib目录下的jar包。

  4. 然后 IntelliJ IDEA 会询问是否添加到现有的 module 中:

  5. 全部设置好后点击OK

添加依赖

如果是先定义的类库,后创建的 module ,那就需要我们手动添加依赖。

打开 Modules 窗口,选择一个 module 添加依赖:

打包设置

定义完类库,添加好依赖,这只能保证编译正常。要想让运行不出错,还需要把类库添加到生成的jar包中。

打开 Artifacts 窗口,在右侧的 Available Elements 列表中找到上面添加的类库。

根据自己的需要选择Put into Output Root/Extract Into Output Root

总结

我们把第三方 jar 包存放在项目中,并通过定义 project 级别的类库进行引用,以保证在团队协作中,项目的依赖关系不丢失。

当然这一切的前提是把 IntelliJ IDEA 的项目文件也放到 VCS 中。稍后我会在另一篇中详细介绍 IntelliJ IDEA 的项目文件管理。

参考

How to manage local libraries in IntelliJ IDEA的更多相关文章

  1. How to add libraries to “External Libraries” in WebStorm/PhpStorm/Intellij

    Stack Overflow Questions Developer Jobs Tags Users   Log In Sign Up Join Stack Overflow to learn, sh ...

  2. Awesome Go精选的Go框架,库和软件的精选清单.A curated list of awesome Go frameworks, libraries and software

    Awesome Go      financial support to Awesome Go A curated list of awesome Go frameworks, libraries a ...

  3. Awesome Go

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  4. Awesome Go (http://awesome-go.com/)

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  5. Docker Resources

    Menu Main Resources Books Websites Documents Archives Community Blogs Personal Blogs Videos Related ...

  6. /etc目录深入理解

    /etc This is the nerve center of your system, it contains all system related configuration files in ...

  7. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

  8. Go 语言相关的优秀框架,库及软件列表

    If you see a package or project here that is no longer maintained or is not a good fit, please submi ...

  9. A Simple Makefile Tutorial

    A Simple Makefile Tutorial A Simple Makefile Tutorial: http://www.cs.colby.edu/maxwell/courses/tutor ...

随机推荐

  1. Create Empty Project In Vs But Not Debug?

    问题描述 在使用VS创建一个空的项目管理,然后,添加项目.可是,这个时候,项目虽然可以运行,但是不能Debug进行调试. 解决方法 按照下面三张图像的设置即可.

  2. Sprint boot notes

    1. spring.io 官网 2. http://javainuse.com/spring/sprboot spring boot学习资源 3. spring boot websocketss视频  ...

  3. hive分隔符总结

    ascii对应的表Char Dec Oct Hex | Char Dec Oct Hex | Char Dec Oct Hex | Char Dec Oct Hex ----------------- ...

  4. http://4526621.blog.51cto.com/4516621/1343369

    http://4526621.blog.51cto.com/4516621/1343369

  5. zTree的简单使用

    理论可以看:http://www.cnblogs.com/shinhwazt/p/5828031.html zTree包:链接:http://pan.baidu.com/s/1eR4xP6M 密码:w ...

  6. HDU2680 Choose the best route 2017-04-12 18:47 28人阅读 评论(0) 收藏

    Choose the best route Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Othe ...

  7. TypeToken 是google提供的一个解析Json数据的类库中一个类

    Type listType = new TypeToken<LinkedList<User>>(){}.getType(); Type是java里的reflect包的Type ...

  8. Git管理

    在bitbucket用git用法 核心流程:从远端中心repo那里git clone到本地,再在本地开发(add,commit),通常会利用branch管理,如果觉得code没问题了,就push到远端 ...

  9. day15(生成器send方法,递归,匿名函数,内置函数)

    一,复习 ''' 1.带参装饰器 - 自定义 | wraps def wrap(info) def outer1(func): from functools import wraps @wraps(f ...

  10. 开源WebGIS实施方案(三):Shapefile数据导入到PostGIS

    PostGIS新版中提供了一个可视化的工具,用于Shapefile数据的导入和导出,极大的方便了使用者的操作. 创建空间数据库 以具有创建用户权限的账号登录pgAdminIII,连接到数据库 创建一个 ...