目录

1、project

2、Module

3、Libraries

4、Facet

5、Artifact

打包成jar包

运行jar


idea project structure modules 中的 language level_配置文件

 

1、project

In the IntelliJ Platform, a project encapsulates all of a project’s source code, libraries, and build instructions into a single organizational unit. Everything done using the IntelliJ Platform SDK is done within the context of a project. A project defines collections referred to as modules and libraries. Depending on the logical and functional requirements for the project, you can create a single-module or a multi-module project.

在IntelliJ平台中,一个“项目”将一个项目的所有源代码、库和指令封装到一个单独的组织单元中。使用IntelliJ平台SDK完成的所有工作。项目定义了称为 模块 和 库 的集合。根据项目的逻辑和功能需求,您可以创建单模块 多模块 项目。

软件开发都要依赖SDK(Software Development Kit),在java应用开发中,就是JDK。

 

idea project structure modules 中的 language level_Java_02

 

2、Module

A module is a discrete unit of functionality that can be run, tested, and debugged independently. Modules include such things as source code, build scripts, unit tests, deployment descriptors, etc. In a project, each module can use a specific SDK or inherit the SDK defined at the project level (see the SDK section below in this document). A module can depend on other modules of the project.

模块是一个独立的功能单元,可以独立地运行、测试和调试。模块包括诸如源代码、构建脚本、单元测试、部署描述符等。在一个项目中,每个模块都可以使用特定的SDK或继承在项目级别定义的SDK。一个模块可以依赖于项目的其他模块。

一个项目可以有一个或多个模块,这些模块都是现有的,可用的。

idea project structure modules 中的 language level_配置文件_03

 

3、Libraries

idea project structure modules 中的 language level_配置文件_04


库是模块可以依赖的已编译代码的集合。在IntelliJ IDEA中,库可以定义为三个层次:

全局(可用于多个项目)、 项目(可用于一个项目中的所有模块) 和 模块(可用于一个模块)。

Java库可以包括类文件、带有类文件的存档和目录,以及带有Java本地库  .dll   .so  或  .jnilib  的目录。

idea project structure modules 中的 language level_配置文件_05

 

 

4、Facet

A facet represents a certain configuration, specific for a particular framework/technology associated with a module. A module can have multiple facets. E.g. Spring specific configuration is stored in a Spring facet.

facet声明了每个模块使用技术的一些配置。一个模块可能有多个facet。Spring模块的配置就声明在Spring facet中。

 

Spring 的主类和配置文件是Spring的一些配置,但是不告诉IDEA在哪他自己是不知道在哪的,所以在facet中就写的很清楚,什么在什么地方。

idea project structure modules 中的 language level_jar_06

 

同样web模块中,他需要配什么?web.xml和webapp目录。因此上面+号添加自己的web.xml在哪。下面添加webapp在哪。
至于真的在哪没关系,一般我们建立/src/main/webapp,但是要记得给web模块配好路径。不然IDEA找不到。

idea project structure modules 中的 language level_Java_07

 

 

5、Artifact

An artifact is an assembly of your project assets that you put together to test, deploy or distribute your software solution or its part. Examples are a collection of compiled Java classes or a Java application packaged in a Java archive, a Web application as a directory structure or a Web application archive, etc.

artifact是您放在一起测试、部署或发布您的软件解决方案或其部分的项目资产的集合。例如,已编译的Java类的集合或打包在Java归档中的Java应用程序、作为目录结构的Web应用程序等等。

artifact就是为了打包成为jar或war的一个配置声明。比如你想分享你的项目给小明,如何分享?自己压缩zip吗?java提供了专门打包的方法,就是jar。

那么如何打包成jar?该jar要打包什么进去?哪些你需要放进去哪些不要?你可以通过Project Structure | Artifacts告诉IDEA。就这么简单。

默认会生成对web exploded的artifact,里面的输出结构指明了项目编译文件该存哪,web资源该复制到哪,lib里要复制什么。

注意,这个lib可以自己选择添加,右边的lib上右键,添加进去就会一并输出了。

idea project structure modules 中的 language level_jar_08

 

idea project structure modules 中的 language level_Java_09

 

 

打包成jar包

刚才讲artifact用于指明如何打包成jar包(或别的),那么现在来试着打包一下。

1、+号,jar,从模型中添加

idea project structure modules 中的 language level_Java_10

 

2、寻找你的主类main class,然后选择对lib中的jar依赖怎么做。第一个选择项是不复制jar依赖,只保留链接关系;第二个是把jar依赖复制到输出目录,和你要打包的jar一起。一般选第二个,这样才能运行你的jar。

第三个配置文件的输出目录,可以不改变。 这些配置文件包括了你的jar的main class是什么啊等等

 

idea project structure modules 中的 language level_jar_11

建立完点ok。

idea project structure modules 中的 language level_jar_12

 

3、bulid artifact
你配好了如何建立artifact,那么开始build吧。

idea project structure modules 中的 language level_jar_13

 

选择jar的build:

idea project structure modules 中的 language level_配置文件_14

 

当然我们选择的是复制依赖到输出目录,因此有很多jar,包括你的example.jar:

idea project structure modules 中的 language level_配置文件_15

 

运行jar

在Run/Bug configuartions里,添加Jar Application

idea project structure modules 中的 language level_jar_16

 

配置JAR Application。告诉他你的jar在哪,并配置自动build。

idea project structure modules 中的 language level_Java_17

 

 

好了,点ok,然后点绿色三角即可运行,效果和你平时运行应该是一样的。 

idea project structure modules 中的 language level_配置文件_18

idea project structure modules 中的 language level_jar_19