Article directory
Module is usually translated as module , and Package is usually translated as package.
1. Python Module and Package
- Python module (Module): 1
.py
file ending
with variables, functions, and classes that can be defined in the module for external use,
such as:from 包.模块 import 函数
,from 包 import 模块
,import 模块
- Python package (Package): essentially a directory (Directory).
When the package is imported, the contents in the package__init__.py
will be executed.
After creating the Python Package , there is still a__init__.py
2. Java Module and Package
- In IDEA, Project is the highest storage directory. When creating a Project, it is accompanied by the creation
src
andpom.xml
creation. After creating the Project, you do not need to create a Model, or you can create multiple Models under the Project. - After the Module is created, it will come
src
with it.pom.xml
Multiple Packages can be created under the Module. - Multiple Java classes can be created under Package
The relationship between Project, Module and Package in IDEA
2.1、Module
Use IDEA to create a Module under Project
After creating the Module, there will be an inheritance relationship pom.xml
between the Module and the Project in the Module.
<parent>
<groupId>org.example</groupId>
<artifactId>project01</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
At the same time, the outermost layer pom.xml
will add modules
information and <packaging>pom</packaging>
<packaging>pom</packaging>
<modules>
<module>module01</module>
<module>module02</module>
</modules>
You can also create a Module under Module, and the child Module will inherit the parent Module.
2.1.1. The significance of sub-module development
Enhance the scalability of the project to facilitate other projects to reference the same functions.
Each module can be independently maintained by different teams.
Split the original module into several sub-modules according to functions to facilitate mutual calls and interface sharing between modules.
2.1.2. Module call
module02
If you want to call it module01
, you need to module02
add pom.xml
dependencies (go there module01
and paste it)
<dependency>
<groupId>org.example</groupId>
<artifactId>module01</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
2.2、Package
Java packages can be multi-layered folders, and the syntax format is:pkg1[.pkg2[.pkg3…]]
JavaPackage
import
Classes in Package can be called using
import org.example.Main;
public class Hello {
public static void main(String[] args) {
Main.main(new String[]{
""});
}
}