Maven的多模块(Multi-Module)工程的pom编写
对于使用maven的骨架创建工程,想必大家都已经熟悉了,这里是一些常用的工程类型,如想看到更多的骨架可以使用mvn的交互式Interactive generate Goal创建指令:mvn archetype:generate
// Creating a simple java application 
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] 
// Creating a webapp 
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-webapp
// Creating a site 
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-site-simple
// Creating a mojo 
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-mojo
// Creating a portlet 
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-portlet
现在想介绍的是多模块的工程的构建。
典型的多模块划分,即按MVC的分层方式来构建多个模块,如工程包括web,business,core3个模块。好我们先看看主工程的pom中应添加些什么,请注意红色文字部分
1.主工程的pom文件中内容:
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.your-company.xxxx</groupId>
    <artifactId>xxxx</artifactId>
    <packaging>pom</packaging> 
    <version>1.0</version>
    <name>xxxx Project</name>
    <url>http://maven.apache.org</url>
<!-- 工程所包含的模块 -->
    <modules> 
        <module>xxxx-core</module>
        <module>xxxx-business</module>
        <module>xxxx-web</module>
    </modules>
2.Web模块的pom文件:
<!-- 父级的pom文件位置 -->
    <parent>
        <groupId>com.your-company.xxxx</groupId>
        <artifactId>xxxx</artifactId>
        <version>1.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <groupId>com.your-company.xxxx</groupId>
    <artifactId>xxxx-web</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>xxxx-web/name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <!-- Application Dependencies -->
        <!-- Web层所依赖的上两层模块 -->
        <dependency>
            <groupId>com.your-company.xxxx</groupId>
            <artifactId>xxxx-core</artifactId>
            <version>${version}</version>
        </dependency>
        <dependency>
            <groupId>com.your-company.xxxx</groupId>
            <artifactId>xxxx-business</artifactId>
            <version>${version}</version>
        </dependency>
...
<dependencies>
3.完成后,mvn eclipse:eclipse后的文件目录为:
xxxx
├─xxxx-core
│ ├─pom.xml 
│ ├─.settings
│ ├─src
│ │ ├─main
│ │ │ ├─java
│ │ │ └─resources
│ │ └─test
│ │      ├─java
│ │      └─resources
│ └─target
│      ├─classes
│      └─test-classes
├─xxxx-business 
│ ├─pom.xml 
│ ├─.settings
│ ├─src
│ │ ├─main
│ │ │ ├─java
│ │ │ └─resources
│ │ └─test
│ │      ├─java
│ │      └─resources
│ └─target
│      ├─classes
│      └─test-classes
├─xxxx-web
│ ├─pom.xml 
│ ├─.settings
│ ├─src
│ │ ├─main
│ │ │ ├─java
│ │ │ └─resources
│ │ └─test
│ │      ├─java
│ │      └─resources
│ └─target
│      ├─classes
│      └─test-classes
|--pox.xml
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号