How to create a MAVEN project and its sub-modules using Eclipse
2012-02-23 14:51 154 People read review (0) Favorite report Eclipse MAVEN server jar
1, first create a parent class engineering Submodule inherits the parent class project and defines the introduced jar and its version in the Pom.xml file of the parent class project can reference
2 Creating API Sub-modules, mainly placing the SDK
3 Creating a server Submodule Primary storage profile does not include source code
Create a project to finish creating a multi-module MAVEN project that supports Eclipse
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:
<packaging>pom</packaging>
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:
<modules>
<module>web-demo</module>
<module>logging-demo</module>
</modules>
It is also automatically added to the Pom.xml file for each submodule:
<parent>
<artifactId>multi-modules-demo</artifactId>
<groupId>com.easymorse.marshal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
The sub-module inherits the total Pom package, which needs to be modified, and the Web-demo module covers:
<packaging>war</packaging>
Logging-demo module revision changed to
<packaging>jar</packaging>
Special settings for superior modules
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.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Special settings for Web sub-modules
The Web sub-module (WEB-DEMO) relies on its log module LOGGING-DEMO. Set Pom.xml:
<dependency>
<groupId>com.easymorse.marshal</groupId>
<artifactId>logging-demo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Web Submodules require WTP support when building eclipse projects, and need to set up Eclipse plug-ins:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
</plugins>
</build>
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: Run Web-demo through the eclipse configuration of Tomcat, run the Web-demo with Maven's Tomcat or jetty plug-in (you need to configure the Pom.xml file), and package your project 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/
or by downloading locally:
[Download not found] Log Reference