Java_maven Build Project (multi-module project)

Source: Internet
Author: User
Tags webhost

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?
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "
  2. xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
  3. <modelversion>4.0.0</modelversion>
  4. <groupId>a</groupId>
  5. <artifactid>b</artifactid>
  6. <version>0.0.1-snapshot</version>
  7. <packaging>pom</packaging>
  8. <distributionmanagement>
  9. <site>
  10. <ID>website</ID>
  11. <URL>scp://webhost.company.com/www/website</url>
  12. </site>
  13. </distributionmanagement>
  14. <properties>
  15. <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
  16. </Properties>
  17. </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?
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "
  2. xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
  3. <modelversion>4.0.0</modelversion>
  4. <groupId>a</groupId>
  5. <artifactid>b</artifactid>
  6. <version>0.0.1-snapshot</version>
  7. <packaging>pom</packaging>
  8. <distributionmanagement>
  9. <site>
  10. <ID>website</ID>
  11. <URL>scp://webhost.company.com/www/website</url>
  12. </site>
  13. </distributionmanagement>
  14. <properties>
  15. <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
  16. </Properties>
  17. <modules>
  18. <module>c</module>
  19. </Modules>
  20. </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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.