How to manage local libraries in IntelliJ IDEA
如何在 IntelliJ IDEA 中管理本地类库
一般来说,如果项目是基于 Maven 管理工具的,我们会在 pom.xml 中添加 dependency 来管理依赖。但有时也会遇到要用的类库不在 Maven Repository 的情况。
比较常见的解决方法是把 JARs 安装到 local repository。这种方法的缺点是,只对本机有效,别人拿到你的代码后不能直接使用。这在团队协作中很不方便。
使用 IntelliJ IDEA 的项目设置可以很容易的解决上面的问题。
下面我给大家演示一下。
定义类库
IntelliJ IDEA 支持定义3种级别的类库:
global
对所有项目有效project
对本项目下所有模块有效module
仅对本模块有效
我推荐定义 project 级别的类库,然后在 module 中引用。
在项目根目录下创建
lib文件夹,并把jar包复制进去。├─.idea
├─lib
│ taobao-sdk-java-auto_1550480258080-20190218.jar
└─src
打开 Project Structure 窗口,选中 Project Settings 下的 Libraries 标签,然后点击右侧的+,选择
Java:

在弹出的窗口中选择
lib目录下的jar包。然后 IntelliJ IDEA 会询问是否添加到现有的 module 中:

全部设置好后点击
OK:

添加依赖
如果是先定义的类库,后创建的 module ,那就需要我们手动添加依赖。
打开 Modules 窗口,选择一个 module 添加依赖:

打包设置
定义完类库,添加好依赖,这只能保证编译正常。要想让运行不出错,还需要把类库添加到生成的jar包中。
打开 Artifacts 窗口,在右侧的 Available Elements 列表中找到上面添加的类库。
根据自己的需要选择Put into Output Root/Extract Into Output Root:

总结
我们把第三方 jar 包存放在项目中,并通过定义 project 级别的类库进行引用,以保证在团队协作中,项目的依赖关系不丢失。
当然这一切的前提是把 IntelliJ IDEA 的项目文件也放到 VCS 中。稍后我会在另一篇中详细介绍 IntelliJ IDEA 的项目文件管理。
参考
- https://www.jetbrains.com/help/idea/library.html
- https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
How to manage local libraries in IntelliJ IDEA的更多相关文章
- 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 ...
- 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 ...
- Awesome Go
A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...
- Awesome Go (http://awesome-go.com/)
A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...
- Docker Resources
Menu Main Resources Books Websites Documents Archives Community Blogs Personal Blogs Videos Related ...
- /etc目录深入理解
/etc This is the nerve center of your system, it contains all system related configuration files in ...
- Automake
Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...
- Go 语言相关的优秀框架,库及软件列表
If you see a package or project here that is no longer maintained or is not a good fit, please submi ...
- A Simple Makefile Tutorial
A Simple Makefile Tutorial A Simple Makefile Tutorial: http://www.cs.colby.edu/maxwell/courses/tutor ...
随机推荐
- 二叉树垂直遍历 · Binary Tree Vertical Order Traversal
[抄题]: 给定二叉树,返回其节点值的垂直遍历顺序. (即逐列从上到下).如果两个节点在同一行和同一列中,则顺序应 从左到右. 给定一个二叉树 {3,9,20,#,#,15,7} 3 /\ / \ 9 ...
- Cook-Torrence Illumination Model 的一些数学说明
Cook-Torrence 光照模型如下: 这个Io就是计算后最终的光强,主要是用来计算镜面反射光,漫反射和环境光的计算和Phong模型一致. F:Fresnel反射系数.主要用来说明反射光强度占入射 ...
- centos6.5修改root密码
转:https://blog.csdn.net/cui1834515/article/details/77860113
- Java Thread系列(十)Future 模式
Java Thread系列(十)Future 模式 Future 模式适合在处理很耗时的业务逻辑时进行使用,可以有效的减少系统的响应时间,提高系统的吞吐量. 一.Future 模式核心思想 如下的请求 ...
- Button或者ImageButton的背景设为透明或者半透明
Button或者ImageButton的背景设为透明或者半透明 半透明<Button android:background="#e0000000" ... /> 透明& ...
- JQuery和JS操作LocalStorage/SessionStorage的方法(转)
出处:http://blog.csdn.net/djzhao627/article/details/50747628 首先说一下LocalStorage和SessionStorage LocalSto ...
- UVa 818Cutting Chains (暴力dfs+位运算+二进制法)
题意:有 n 个圆环,其中有一些已经扣在一起了,现在要打开尽量少的环,使所有的环可以组成一条链. 析:刚开始看的时候,确实是不会啊....现在有点思路,但是还是差一点,方法也不够好,最后还是参考了网上 ...
- Jmeter Cookie管理器 获取JSESSIONID
1.打开jmeter.抓包添加Web请求后,添加Cookie管理器.直接添加就行.值要不要都一样 添加值:${COOKIE_JSESSIONID 域:${server} 2.点击载入到当前脚本 3.到 ...
- DE0-Nano-SoC开发板诡异的电源电路方案设计分析
这些日子一直在设计自己的Cyclone V SoC开发板,由于我们这种散兵游勇,是断然没有厂家和代理技术支持的,因此只能找各种现成方案参考.其实Cyclone V SoC芯片的外围电路设计不难,无非就 ...
- polymer技巧
1.添加一个div元素 我们完全可以自己造一个这样的东西出来,比如下面例子我们给 div 元素添加一个 is="demo-test" <script> var Poly ...