Project 和 Module 介绍

这两个概念是 IntelliJ IDEA 的必懂知识点之一,请务必要学会。

如果你是 Eclipse 用户,并且已经看了上面给的链接,那 IntelliJ IDEA 首先告诉你一个非常重要的事情:IntelliJ IDEA 没有类似 Eclipse 工作空间(workspace)的概念的。很多从 Eclipse 转过来的人总是下意识地要再同一个窗口管理 n 个项目,这在 IntelliJ IDEA 是无法得到。IntelliJ IDEA 提供的体验是:一个 Project 打开一个 Window 窗口。

对于 Project,IntelliJ IDEA 是这样解释的:

  • Whatever you do in IntelliJ IDEA, you do that in the context of a project. A project is an organizational unit that represents a complete software solution. It serves as a basis for coding assistance, bulk refactoring, coding style consistency, etc.
  • Your finished product may be decomposed into a series of discrete, isolated modules, but it's a project definition that brings them together and ties them into a greater whole.
  • Projects don't themselves contain development artifacts such as source code, build scripts, or documentation. They are the highest level of organization in the IDE, and they define project-wide settings as well as collections of what IntelliJ IDEA refers to as modules and libraries.

对于 Module,IntelliJ IDEA 是这样解释的:

  • A module is a discrete unit of functionality which you can compile, run, test and debug independently.
  • Modules contain everything that is required for their specific tasks: source code, build scripts, unit tests, deployment descriptors, and documentation. However, modules exist and are functional only in the context of a project.
  • Configuration information for a module is stored in a .iml module file. By default, such a file is located in the module's content root folder.
  • Development teams, normally, share the .iml module files through version control.

通过上面的介绍我们知道,在 IntelliJ IDEA 中 Project 是最顶级的级别,次级别是 Module。一个 Project 可以有多个 Module。目前主流的大型项目结构都是类似这种多 Module 结构,这类项目一般是这样划分的,比如:core Module、web Module、plugin Module、solr Module 等等,模块之间彼此可以相互依赖。通过这些 Module 的命名也可以看出,他们之间应该都是处于同一个项目业务情况下的模块,彼此之间是有不可分割的业务关系的。

所以我们现在总结:一个 Project 是由一个或多个 Module 组成,模块之间尽量是处在同一个项目业务的的情况下,彼此之间互相依赖关联。这里用的是 尽量,因为 IntelliJ IDEA 的 Project 是一个没有具备任何编码设置、构建等开发功能的,主要起到一个项目定义、范围约束、规范等类型的效果,也许我们可以简单地理解为就是一个单纯的目录,只是这个目录命名上必须有其代表性的意义。

下面我们以著名的 spring-framework 项目为例介绍多 Module 的结构的:

  • 项目主页:https://github.com/spring-projects/spring-framework
  • 该项目的 Project 命名是:spring-framework。该目录主要作用为各个 Module 的顶层目录进行约束,告诉协同者,这个目录下都是 spring-framework 相关的,我绝不对放 Android 相关源码、文档、文件在上面的。该目录并不是以一个实际性的目录来提现的,所以你访问主页是看不到的,但是当你 checkout 的时候,你必须为这个项目命名,至于命名默认就是 spring-framework
  • Project 下有二十来个 Module,各个 Module 的命名也是有含义的,比如:spring-corespring-jdbcspring-jmsspring-ormspring-webspring-webmvc 等等,我们通过这些命名也能清楚地知道他们要表达的含义,这些 Module 下也都各自有 src 编码目录,可以自行编码和构建。

  • 相比较于多 Module 项目,小项目就无需搞得这么复杂。只有一个 Module 的结构 IntelliJ IDEA 也是支持的,并且 IntelliJ IDEA 创建项目的时候,默认就是单 Module 的结构的。
  • 如上图 Gif 图演示,在输入 Project name 的时候,Module nameModule file Location 自动进行改变,同时 Project locationModule file Location 完全一样,这也就表示,Project 目录和 Module 目录是同一个,所以此时 Project 目录下就会有 src 目录,但是我们应该明白其本质还是 Module 的目录。

关于 IntelliJ IDEA 的 Project 和 Module 终于解释清楚了,但是由于 IntelliJ IDEA 官网上又有一段话对此解释得不够好,特别是对 Eclipse 用户来讲:https://www.jetbrains.com/idea/help/eclipse-faq.html,其中有这样两句话:

  • An Eclipse workspace is similar to a project in IntelliJ IDEA
  • An Eclipse project maps to a module in IntelliJ IDEA

你可以把 IntelliJ IDEA 的 Project 当做 workspace 使用,IntelliJ IDEA 也是支持的,但是就像我们前面解释的那么那么多,这样是非常不符合其初衷的,所以请别把这段话当做教义去学习。对此 zeroturnaround 的大牛也有针对此进行了说明:http://zeroturnaround.com/rebellabs/getting-started-with-intellij-idea-as-an-eclipse-user/3/

在一个项目下新建Module(模块)就可以实现项目下面新建项目了。

Project和Module的介绍的更多相关文章

  1. 十、IntelliJ IDEA 中 Project 和 Module 的概念及区别

    在 IntelliJ IDEA 中,没有类似于 Eclipse 工作空间(Workspace)的概念,而是提出了Project和Module这两个概念.接下来,就让咱们一起看看 IntelliJ ID ...

  2. 【转】 IntelliJ IDEA 中 Project 和 Module 的概念及区别

    原文地址:https://blog.csdn.net/qq_35246620/article/details/65448689 在 IntelliJ IDEA 中,没有类似于 Eclipse 工作空间 ...

  3. IntelliJ IDEA 创建项目project和module的关系

    使用基于IntelliJ的IDE,如phpstorm.android studio都会对project和module的关系比较糊涂.用简单的一句话来概括是:IntelliJ系中的Project相当于E ...

  4. IntelliJ IDEA 14.x 的 project 和 module 是啥关系?

    使用基于IntelliJ的IDE,如phpstorm.android studio都会对project和module的关系比较糊涂,简单的概括如下: IntelliJ系中的 Project 相当于Ec ...

  5. Android中Project、Module的区别

    Project 可以包含多含 Module. Project相当于eclipse里面的工作区间,module相当于其project.module可以作为狭义上的模块,可以多个app共用的module. ...

  6. Android 培训准备资料之project与module的区别(1)

    project和module的区别? 现在我们来看看在Android studio中怎样新建一个project (1)file->new->new project. Application ...

  7. Android Studio导入github下载的project和module

    前言:我们以前eclispe时代, 经常都是跑到github浏览第三方开源资源,然后下载下来,运行一下sample之类的,学习没有接触的第三方安卓库,但是到了Android Studio,在githu ...

  8. Android Studio导入Project、Module的正确方法

    Gradle Project项目.Module模块导入 最近看到网上很多人在抱怨,Android Studio很难导入github上下载下来的一些项目,主要包括: 1.导入就在下载Gradle2.根本 ...

  9. Android Studio中关于Project与Module

    在Android Studio中一个Project和Eclipse中的WorkSpace是相似的,而一个Module与Eclipse中的Project是相似的(大致可以这么的认为) 若在Android ...

随机推荐

  1. dom jaxp详解

    转自 http://blog.csdn.net/java958199586/article/details/7277904 一.XML解析技术概述 1.XML解析方式分为两种:dom和sax (1)d ...

  2. redirect模块的秘密

    所有的redirect记录都在config/url_directs下面, 但是某个node/edit的redirect记录只包含redirect到自己的记录,且不验证url的合理性. 现在比如,a跳转 ...

  3. genymotion是一款完全超越BlueStacks

    今天给大家推荐一款超赞的神器:genymotion. 一:什么是genymotion      genymotion是一款完全超越BlueStacks的安卓模拟器,正如它中文官网的介绍:快到极致的An ...

  4. css制作简单的导航栏

    //css代码 #menu{ height: 65px; width:100%; background-color: rgba(0, 0, 0, 0.5);}#menu ul{ list-style: ...

  5. robotframework笔记26

    测试数据文档工具(Testdoc) Testdoc是机器人框架内置的工具生成高水平 根据测试用例文档. 创建的文档是在HTML中 格式和它包括名称.文档和其他元数据 测试套件和测试用例,以及和他们的顶 ...

  6. [maven] settings 文件节点配置详解

    基本结构 <settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3. ...

  7. bug:C#线程间操作无效: 从不是创建控件" XX" 的线程访问它

    今天遇到这个问题,百度了下,把解决的方法总结出来.我们在ui线程创建的子线程操作ui控件时,系统提示错误详细信息为:线程间操作无效: 从不是创建控件“XXX”的线程访问它. 就我知道的有三种方法,先看 ...

  8. 164. Maximum Gap *HARD* -- 无序数组找出排序后连续元素的最大间隔

    Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...

  9. html5的标签

    1.article与section div的区别 当一个标签只是为了样式化或者方便脚本使用时,应该使用 div . section 表示一段专题性的内容,一般会带有标题.,section 应用的典型场 ...

  10. JavaScript之模块化编程

    前言 模块是任何大型应用程序架构中不可缺少的一部分,模块可以使我们清晰地分离和组织项目中的代码单元.在项目开发中,通过移除依赖,松耦合可以使应用程序的可维护性更强.与其他传统编程语言不同,在当前Jav ...