Java zero-based self-study website, click to understand: https://how2j.cn
Aliyun server, click to learn: https://www.aliyun.com/minisite/goods
table of Contents
Step 1: parent-child-aggregate project
Step 14: pom.xml of the subproject
Step 15: pom.xml of the parent project
Step 1: parent-child-aggregate project
Through maven, you can create parent-child-aggregation projects. The so-called parent-child project means that there is one parent project and multiple sub-projects.
These sub-projects, in terms of business logic, are all summarized under this parent project, and generally speaking, there will be repeated jar package sharing.
Therefore, the common practice is to place the duplicate jar packages under the parent project for dependency, so the subproject does not need to rely on these duplicate jar packages.
Step 2: Create a new project
Step 3: select maven project
1. Select Maven on the left
2. Check Create from archetype
3. Select org.apache.maven.archetypes:maven-archetype-quickstart
4. Next
Step 4: project parameters
Enter the project parameters as shown
Step 5: maven settings
After the IDEA settings of the previous knowledge point , you can see the maven settings as shown in the figure
Step 6: project location
As shown in the figure, then click Finish
Step 7: modify pom.xml
The pom.xml automatically generated by idea has a lot of things, many of which are not needed. Amend to the following content.
1. The default is jar, modified to pom. Only then can it exist as a parent project.
|
2. Increase the dependency of hutool jar and junit package for observing the invocation of it in subsequent subprojects.
|
Step 8: create subproject
The so-called subproject is actually a maven module.
Right-click on parentMavenProject->New->Module.
Step 9: select simple items
1. Select Maven on the left
2. Check Create from archetype
3. Select org.apache.maven.archetypes:maven-archetype-quickstart
4. Next
Step 10: project parameters
Enter ArtifactId: childMavenProject
Step 11: maven settings
Next is the same maven setting
Step 12: project directory
As shown in the figure, then click Finish.
Step 13: TestHutool
Create a new TestHutool class under childMavenProject and run it.
It can be found that the classes in the hutool jar can be used. This shows that the child project can use the jar package in the parent project.
|
Step 14: pom.xml of the subproject
Observing the pom.xml of the child project, you can find that it has an additional parent, which is a dependency on the parent project.
|
Step 15: pom.xml of the parent project
At this time, open the pom.xml of the parent project, you can find that it has such a module s, which means the association to the sub-project.
|
Step 16: project structure
Observing the directory structure, you can find that childMavenProject is located under parentMavenProject. So if there are childMavenProject1, childMavenProject2, childMavenProject3 in the future, they will also be placed in such a directory, which is convenient for management.
Step 17: Run the project
In the download area (click to enter), there is a runnable project download corresponding to this knowledge point. If you really can't figure it out by yourself, just download and unzip it for comparison.
For more information, click to understand: https://how2j.cn/k/idea/idea-parent-child/2051.html