- 创建父项目common-parent
- File>>New>>Project>>Empty Project>>填写项目名称和项目路径>>Finish
- File>>New>>Module>>选择maven>>Create from archetype>>maven-archetype-quickstart>>Next>>GroupId>>ArtifactId>>Next>>Maven home dictory>>User setting file>>Override>>Next>>Module name[common-parent]>>Content root>>Next>>等待生成pom文件
- 修改pom.xml文件
<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>co.mico</groupId> <artifactId>common-parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging><!--修改打包方式--> <name>common-parent</name> <url>http://maven.apache.org</url> <!--集中定义依赖版本号--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <junit.version>4.12</junit.version> ...(省略) </properties> <dependencyManagement> <dependencies> <!-- 时间操作组件 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>${joda-time.version}</version> </dependency> ...(省略) </dependencyManagement> <build> <finalName>${project.artifactId}</finalName> <plugins> <!-- 资源文件拷贝插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- java编译插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
- 创建子项目公共工具类common-utils
- 公共工具类是继承自父项目common-parent
- File>>New>>Module>>选择maven>>Create from archetype>>maven-archetype-portlet>>Add as module to [这里选择none]>>Parent[这里是cn.william.common-parent] >>GroupId>>ArtifactId>>Next>>Maven home dictory>>User setting file>>Override>>Next>>Module name[common-utils]>>Content Root[注意修改目录结构,common-parent同级目录]>>Next>>等待生成pom文件
- 修改pom文件,打包方式为jar
<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"> <parent> <artifactId>common-parent</artifactId> <groupId>cn.william</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../common-parent/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>common-utils</artifactId> <packaging>jar</packaging><!-- 打成jar包 --> <name>common-utils</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- jar包的依赖 --> <dependencies> <!-- 时间操作组件 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> </dependency> ...(省略) </dependencies> </project>
- 创建子项目taotao-manager[开发项目],与工具类的创建方式一致,打包方式为pom
<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"> <parent> <artifactId>common-parent</artifactId> <groupId>cn.william</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../common-parent/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>uncertain-manager</artifactId> <packaging>pom</packaging> <name>uncertain-manager</name> <url>http://maven.apache.org</url> <modules> <module>taotao-manager-pojo</module> <module>taotao-manager-mapper</module> <module>taotao-manager-service</module> <module>taotao-manager-web</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- 依赖管理 --> <dependencies> <dependency> <groupId>cn.william</groupId> <artifactId>common-utils</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <!-- 配置插件 --> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin> </plugins> </build> </project>
- 创建开发项目的子项目taotao-manager-pojo
- 选中ncertain-manager项目>>New>>>>选择maven>>Create from archetype>>maven-archetype-quickstart>>Add as module to [这里选择cn.william.uncertain-manager]>>Parent[这里是cn.william.uncertain-manager] >>GroupId>>ArtifactId>>Next>>Maven home dictory>>User setting file>>Override>>Next>>Module name[uncertain-manager-pojo]>>Content Root[注意修改目录结构,uncertain-manager下级目录]>>Next>>等待生成pom文件
- 修改pom文件
<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"> <parent> <artifactId>taotao-manager</artifactId> <groupId>cn.william</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager-pojo</artifactId> <packaging>jar</packaging> <name>taotao-manager-pojo</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> </project>
- 创建开发项目的子项目taotao-manager-mapper,创建方式与pojo项目一致,打包方式也为jar,但是mapper项目依赖pojo项目:
- pom文件依赖配置
<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"> <parent> <artifactId>taotao-manager</artifactId> <groupId>cn.william</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager-mapper</artifactId> <packaging>jar</packaging> <name>taotao-manager-mapper</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- 依赖与pojo子模块 --> <dependency> <groupId>cn.william</groupId> <artifactId>taotao-manager-pojo</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> </dependencies> </project>
- pom文件依赖配置
- 创建开发项目的子项目taotao-manager-service,创建方式与pojo项目一致,打包方式也为jar,但是service项目依赖mapper项目:
- pom文件
<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"> <parent> <artifactId>taotao-manager</artifactId> <groupId>cn.william</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager-service</artifactId> <packaging>jar</packaging> <name>taotao-manager-service</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- 依赖与mapper子模块 --> <dependency> <groupId>cn.william</groupId> <artifactId>taotao-manager-mapper</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> ...(省略) </dependencies> </project>
- 创建开发项目的子项目taotao-manager-web,创建方式与pojo项目一致,打包方式为war,archetype是maven-archetype-quickstart,web项目依赖service项目
- pom文件配置
<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/maven-v4_0_0.xsd"> <parent> <artifactId>taotao-manager</artifactId> <groupId>cn.william</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taotao-manager-web</artifactId> <packaging>war</packaging><!--打成war包--> <name>taotao-manager-web Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <!-- 依赖于service --> <dependency> <groupId>cn.william</groupId> <artifactId>taotao-manager-service</artifactId> <version>1.0-SNAPSHOT</version> </dependency> ...(省略) </dependencies> <build> <finalName>taotao-manager-web</finalName> </build> </project>
- 运行
- web项目下新建index.jsp
- 确保taotao-manager的pom中配置了tomcat的插件
<build> <!-- 配置插件 --> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin> </plugins> </build>
- Run>>Edit Configurations>>Add New Configurations>>Maven>>Name[taotao-manager]>>Working directory[taotao-manger项目的目录]>>Command line[clean tomcat7:run]
- Run之前先将所有模块安装一下
- 图文原文:基于maven使用IDEA创建多模块项目
IDEA maven3 构建多模块项目
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 简书 Wwwwei转载请注明原创出处,谢谢! 一些概念 Maven 一个项目管理工具,简单的理解为一种标准化的方式...
- 我jdk版本是1.7.0_95,在网上查了一下1.7属于java7maven3.3+版本都支持java7,所以我使...