Build a Maven project under Eclipse, which consists of multiple sub-modules.
1. Create a parent project
New-->project-->maven-->maven project, click Next to enter new MAVEN project's Select project name and location interface
, do nothing directly next to the select an archetype interface.
Select Maven-archetype-site-simple in this interface, then select next to enter the interface of the Select Enter a group ID for the artifact
, enter your group and artifact names in the group ID and artifact ID. I use a and B respectively, choose to complete. A project is generated in eclipse with the project name B.
At this point, the pom file for B is as follows:
[HTML]View Plaincopyprint?
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "
- xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
- <modelversion>4.0.0</modelversion>
- <groupId>a</groupId>
- <artifactid>b</artifactid>
- <version>0.0.1-snapshot</version>
- <packaging>pom</packaging>
- <distributionmanagement>
- <site>
- <ID>website</ID>
- <URL>scp://webhost.company.com/www/website</url>
- </site>
- </distributionmanagement>
- <properties>
- <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
- </Properties>
- </Project>
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelversion>4.0.0</modelversion> <groupId>A</groupId> <artifactid>b</ artifactid> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <distributionManagement> <site> <id>website</id> <url>scp:// webhost.company.com/www/website</url> </site> </distributionManagement> < properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </ Properties></project>
2. Creating sub-projects
2.1 Delete the src file in Project B (optional, mainly for personal needs) 2.2 Select item B, right-click, select New-->project-->maven-->maven Module, click Next, Enter the name of the submodule in the interface that appears C, click Next, the Select an archetype interface appears. At this point, select Maven-archetype-site-quickstart or Maven-archetype-webapp (used when building the Web tier) and select Finish, which is to generate subproject C.
Then B's Pom file becomes this (and the above is more than just a modules tag):
[HTML]View Plaincopyprint?
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "
- xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
- <modelversion>4.0.0</modelversion>
- <groupId>a</groupId>
- <artifactid>b</artifactid>
- <version>0.0.1-snapshot</version>
- <packaging>pom</packaging>
- <distributionmanagement>
- <site>
- <ID>website</ID>
- <URL>scp://webhost.company.com/www/website</url>
- </site>
- </distributionmanagement>
- <properties>
- <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
- </Properties>
- <modules>
- <module>c</module>
- </Modules>
- </Project>
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelversion>4.0.0</modelversion> <groupId>A</groupId> <artifactid>b</ artifactid> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <distributionManagement> <site> <id>website</id> <url>scp:// webhost.company.com/www/website</url> </site> </distributionManagement> < properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </ properties> <modules> <module>C</module> </modules></project>
The sub-project of Build B is completed, and the other subproject is constructed similar to this.
When building the second sub-project D may not appear in a timely manner in B, just the B project can be refreshed.
Ps:
In fact, when building a multi-module project, you can select any type when you select the type of the parent project. The interface for selecting the project type is as follows:
For these unconventional types of projects, you need to make the following changes if you want to be a parent project:
1. Change the <packaging>jar</packaging> in Pom.xml file to <packaging>pom</packaging> If you do not change to Pom then the parent project will produce a target file when packaging, if there is no <packaging>pom</packaging> can be in the <version>0.0.1-SNAPSHOT< Add this sentence after the/version>.
2. Remove all files except Pom.xml, where the JRE System library cannot be deleted directly, need to select, and right-click Bulid path-->remove from Bilud Path to remove.
At this time the parent project looks very clean and tidy.
In fact, in the ordinary project is not allowed to build sub-modules, whether to create sub-modules under a project, mainly depends on whether there is <packaging>pom</packaging> this configuration. If you have this configuration, any project can create sub-modules, hard to create the whole project will become nondescript. It seems that Maven is deciding whether a project can create submodules is actually dependent on this configuration.
Java_maven Build Project (multi-module project)