Create a multi-module MAVEN project that supports eclipse

Source: Internet
Author: User

MAVEN allows you to create projects with multiple associated modules (multiple module Projects). Consists of a total module, which contains several sub-modules (Submodules can also contain submodules). This MAVEN feature supports large-scale project builds, and often large projects consist of many sub-modules.

Below is a description of how to create a multi-module MAVEN project under Eclipse.

Create a total pom

MVN Archetype:create-dgroupid=com.easymorse.marshal-dartifactid=multi-modules-demo

Create a MAVEN project, and then modify the project's Pom.xml file, the package type to POM:

Pom

and delete the SRC directory.

To create a sub-module

In the total module directory, create sub-modules, such as Web-demo:

MVN Archetype:create-dgroupid=com.easymorse.marshal-dartifactid=web-demo

Then create a log module such as:

MVN Archetype:create-dgroupid=com.easymorse.marshal-dartifactid=logging-demo

Added automatically in the Pom.xml file of the total pom:

  Web-demo  Logging-demo
It is also automatically added to the Pom.xml file for each submodule:



Multi-modules-demo

Com.easymorse.marshal

1.0-snapshot

The sub-module inherits the total Pom package, which needs to be modified, and the Web-demo module covers:

War

Logging-demo module revision changed to

Jar

Special settings for the parent module

You need to set the Java compilation parameters in the parent module, and now eclipse generally uses the newer version, the default JDK is 1.6, and Maven defaults to 1.4.



Maven-compiler-plugin

1.6

1.6

UTF-8

Special settings for Web sub-modules

The Web sub-module (WEB-DEMO) relies on its log module LOGGING-DEMO. Set Pom.xml:



Com.easymorse.marshal

Logging-demo

1.0-snapshot

Web Submodules require WTP support when building eclipse projects, and need to set up Eclipse plug-ins:



Org.apache.maven.plugins

Maven-eclipse-plugin

True

True

2.0

Build Eclipse Project

Under the Multi-modules-demo Project root directory:

MVN Eclipse:eclipse

Then, importing through Eclipse's Import project, you can find two items:

    1. Logging-demo
    2. Web-demo

are imported in. The import may have an error, mainly because the classpath variable "M2_repo" is not set, so you can set this class variable to MAVEN's local repository.

If you want to use M2eclipse in eclipse, you need to use:

MVN Eclipse:m2eclipse

This makes it unnecessary to set the M2_repo class library variable.

Next

Next you can:

    1. Tomcat run Web-demo configured with eclipse;
    2. Run Web-demo with Maven's Tomcat or jetty plugin (requires configuration of pom.xml files);
    3. Package projects for easy distribution and deployment.
Download the source code

This article source code see:

http://easymorse.googlecode.com/svn/tags/multi-modules-demo_1.0.0/

Create a multi-module MAVEN project that supports eclipse

Related Article

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.