此文已由作者赵计刚授权网易云社区发布。
欢迎访问网易云社区,了解更多网易技术产品运营经验。
2.1、maven父子模块
在实际开发中,我们基本都会用maven父子分模块的方式进行项目的开发。
2.2、实际操作
2.2.1、手工建立一个ssmm0的文件夹,并在该文件夹中加入一个pom.xml文件,该pom.xml文件内容如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.xxx</groupId> 8 <artifactId>ssmm0</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 11 <name>ssmm0</name> 12 <packaging>pom</packaging><!-- 父模块 --> 13 14 <!-- 管理子模块 --> 15 <modules> 16 <module>ssmm</module> 17 </modules> 18 19 <properties> 20 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 21 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 22 </properties> 23 </project>
注意:
2.2.2、将上一章建好的那个项目ssmm放入ssmm0文件夹下,修改pom.xml如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4 5 <modelVersion>4.0.0</modelVersion> 6 7 <!-- 指定父模块 --> 8 <parent> 9 <groupId>com.xxx</groupId> 10 <artifactId>ssmm0</artifactId> 11 <version>1.0-SNAPSHOT</version> 12 </parent> 13 14 <groupId>com.xxx.ssmm0</groupId> 15 <artifactId>ssmm0-ssmm</artifactId> 16 <!--<version>1.0-SNAPSHOT</version>--><!-- 父模块已经指定了版本号,这里就不用了--> 17 18 <name>ssmm0-ssmm</name> 19 <packaging>war</packaging> 20 21 <properties> 22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 23 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 24 </properties> 25 26 <!-- 引入实际依赖 --> 27 <dependencies> 28 <!-- json --> 29 <dependency> 30 <groupId>com.alibaba</groupId> 31 <artifactId>fastjson</artifactId> 32 <version>1.1.39</version> 33 </dependency> 34 <!-- servlet --> 35 <dependency> 36 <groupId>javax.servlet</groupId> 37 <artifactId>javax.servlet-api</artifactId> 38 <version>3.0.1</version> 39 <scope>provided</scope> 40 </dependency> 41 <!-- spring --> 42 <dependency> 43 <groupId>org.springframework</groupId> 44 <artifactId>spring-core</artifactId> 45 <version>3.2.6.RELEASE</version> 46 </dependency> 47 <dependency> 48 <groupId>org.springframework</groupId> 49 <artifactId>spring-beans</artifactId> 50 <version>3.2.6.RELEASE</version> 51 </dependency> 52 <dependency> 53 <groupId>org.springframework</groupId> 54 <artifactId>spring-context</artifactId> 55 <version>3.2.6.RELEASE</version> 56 </dependency> 57 <dependency> 58 <groupId>org.springframework</groupId> 59 <artifactId>spring-web</artifactId> 60 <version>3.2.6.RELEASE</version> 61 </dependency> 62 <dependency> 63 <groupId>org.springframework</groupId> 64 <artifactId>spring-webmvc</artifactId> 65 <version>3.2.6.RELEASE</version> 66 </dependency> 67 <!-- 这个是使用velocity的必备包 --> 68 <dependency> 69 <groupId>org.springframework</groupId> 70 <artifactId>spring-context-support</artifactId> 71 <version>3.2.6.RELEASE</version> 72 <scope>compile</scope> 73 </dependency> 74 <!-- mysql --> 75 <dependency> 76 <groupId>mysql</groupId> 77 <artifactId>mysql-connector-java</artifactId> 78 <version>5.1.27</version> 79 <scope>runtime</scope> 80 </dependency> 81 <!-- 数据源 --> 82 <dependency> 83 <groupId>org.apache.tomcat</groupId> 84 <artifactId>tomcat-jdbc</artifactId> 85 <version>7.0.47</version> 86 </dependency> 87 <!-- mybatis --> 88 <dependency> 89 <groupId>org.mybatis</groupId> 90 <artifactId>mybatis</artifactId> 91 <version>3.1.1</version> 92 </dependency> 93 <dependency> 94 <groupId>org.mybatis</groupId> 95 <artifactId>mybatis-spring</artifactId> 96 <version>1.1.1</version> 97 </dependency> 98 <!-- velocity --> 99 <dependency> 100 <groupId>org.apache.velocity</groupId> 101 <artifactId>velocity</artifactId> 102 <version>1.5</version> 103 </dependency> 104 <dependency> 105 <groupId>velocity-tools</groupId> 106 <artifactId>velocity-tools-generic</artifactId> 107 <version>1.2</version> 108 </dependency> 109 <!-- 用于加解密 --> 110 <dependency> 111 <groupId>commons-codec</groupId> 112 <artifactId>commons-codec</artifactId> 113 <version>1.7</version> 114 </dependency> 115 <dependency> 116 <groupId>org.bouncycastle</groupId> 117 <artifactId>bcprov-jdk15on</artifactId> 118 <version>1.47</version> 119 </dependency> 120 <!-- 集合工具类 --> 121 <dependency> 122 <groupId>org.apache.commons</groupId> 123 <artifactId>commons-collections4</artifactId> 124 <version>4.0</version> 125 </dependency> 126 <!-- http --> 127 <dependency> 128 <groupId>org.apache.httpcomponents</groupId> 129 <artifactId>httpclient</artifactId> 130 <version>4.2.6</version> 131 </dependency> 132 </dependencies> 133 </project>
注意:在上一章的基础上做了以下几点修改
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties>
建议:
这几点建议,在我们编写和部署项目的时候都一目了然;以上几点建议,请对照着以上两个pom.xml文件对号入座。
2.2.3、在ssmm0的文件夹中,即父模块pom.xml所在的文件夹中运行命令窗口,执行"mvn clean compile"命令
2.2.4、编译成功后,将项目ssmm0以maven项目引入eclipse(具体方法:见第一章)
引入的项目结构如下:
注意:
免费领取验证码、内容安全、短信发送、直播点播体验包及云服务器等套餐
更多网易技术、产品、运营经验分享请点击。