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:
- Logging-demo
- 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:
- Tomcat run Web-demo configured with eclipse;
- Run Web-demo with Maven's Tomcat or jetty plugin (requires configuration of pom.xml files);
- 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