自己对maven工程下各个模块的解读

对各个模块进行讲解:
1、parent工程:

在parent的pom.xml下:

集中对版本进行控制

<!-- 集中定义依赖版本号 -->
	<properties>
		<spring.version>4.3.8.RELEASE</spring.version>
		<spring-data-redis.version>1.8.7.RELEASE</spring-data-redis.version>
		<mybatis.version>3.2.8</mybatis.version>
		<mybatis.spring.version>1.2.2</mybatis.spring.version>
		<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
		<mysql.version>5.1.41</mysql.version>
		<slf4j.version>1.7.21</slf4j.version>
		<jackson.version>2.7.4</jackson.version>
		<!-- 连接池 阿里巴巴数据源 全世界最牛逼的data source 没有之一 -->
		<druid.version>1.1.0</druid.version>
		<httpclient.version>4.3.5</httpclient.version>
		<commons.httpclient.version>3.1</commons.httpclient.version>
		<jstl.version>1.2</jstl.version>
		<servlet-api.version>2.5</servlet-api.version>
		<jsp-api.version>2.0</jsp-api.version>
		<joda-time.version>2.5</joda-time.version>
		<commons-lang3.version>3.3.2</commons-lang3.version>
		<commons-io.version>1.3.2</commons-io.version>
		<commons-net.version>3.3</commons-net.version>
		<pagehelper.version>4.1.3</pagehelper.version>
		<commons-fileupload.version>1.3.1</commons-fileupload.version>
		<jedis.version>2.9.0</jedis.version>
		<apache-commons-pool2>2.4.2</apache-commons-pool2>
		<log4j.version>1.2.16</log4j.version>
		<zookeeper.version>3.4.11</zookeeper.version>
		<curator.version>4.0.0</curator.version>
	</properties>


<!-- 只定义依赖的版本,不会实际依赖 -->
	<dependencyManagement>
		<dependencies>
<!-- Mybatis -->
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
				<version>${mybatis.version}</version>
			</dependency>
	</dependencies>
	</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.2</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
		</plugins>
		<pluginManagement>
			<plugins>
				<!-- 配置Tomcat插件 -->
				<plugin>
					<groupId>org.apache.tomcat.maven</groupId>
					<artifactId>tomcat7-maven-plugin</artifactId>
					<version>2.2</version>
				</plugin>

				<!-- 配置sts插件 -->
				<plugin>
					<artifactId>maven-eclipse-plugin</artifactId>
					<version>2.9</version>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>

<!--子模块-->
<modules>
  	<module>zsl-maven-test-common</module>
  	<module>zsl-maven-test-pojo</module>
  	<module>zsl-maven-test-mapper</module>
  	<module>zsl-maven-test-service</module>
  	<module>zsl-maven-test-web</module>
  </modules>

Parent是聚会工程里所有的父类,因为依赖传递所以在parent定义的依赖会传递给他的子模块
2、common

一般第三方工具类依赖加在这里
例如:

<dependencies>
		<!-- Apache工具组件 -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-io</artifactId>
		</dependency>
		<dependency>
			<groupId>commons-net</groupId>
			<artifactId>commons-net</artifactId>
		</dependency>
	</dependencies>

3、pojo

Pojo依赖于common,可以通过查看Maven Dependecies快速查看到它的依赖

它的pom.xml一般没什么可以加的依赖

3、mapper

Mapper加入pojo进行依赖,但是pojo加了common,因为依赖的传递所以这里可以看到加了common和pojo
它的pom.xml,因为是mapper,持久层的映射所以加的依赖多与数据库持久化相关

  <dependencies>	
  	<dependency>
  		<groupId>com.wxadmin</groupId>
  		<artifactId>wxd-videos-admin-pojo</artifactId>
  		<version>0.0.1-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>

这里要重点讲解一下:

<build>
		<resources>
			<!-- 如果不加,那么打包的时候mapper文件不会被加载进来 -->
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
				</includes>
				<filtering>false</filtering>
			</resource>
		</resources>
	</build>

因为我们的资源文件是放在mapper下面的,如果在项目打包发布的时候,不加上,它打包的时候是不会自动把mapper下面的进行打包的,项目启动会报错,加上这里,会把配置文件和资源文件一起进行打包。

4、service

使用Spring框架一般要加入一下几种核心依赖

<dependencies>
  	<dependency>
  		<groupId>com.wxadmin</groupId>
  		<artifactId>wxd-videos-admin-mapper</artifactId>
  		<version>0.0.1-SNAPSHOT</version>
  	</dependency>
  	
  	<!-- Spring -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
		</dependency>
  </dependencies>

5、web(控制层),war包

当你Run As -----》 Maven install后

就打包成功

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

偷偷学习被我发现

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值