maven高级
ssm分模块开发
pom文件,有各种示例代码
虽然长,但是包括了各种需要的代码,总结一下:
1.模块聚合
2.模块继承,避免了版本不一致问题
3.自定义属性,可以将版本通过${}来共同指定,这样就不需要一个个找
4.多环境配置资源,通过<resources>和<testResources>标签来加载资源,再通过
环境配置id来指定开发环境
5.依赖管理,导入所有需要的依赖以及子工程的依赖
6.跳过部分测试,可以快速测试自己的模块
7.上传私服,通过nexus,需要在settings.xml进行配置
8.如果帮助到您就鼓励一下我吧,啾咪!
<?xml version="1.0" encoding="UTF-8"?>
<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>com.lzb</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<!--聚合其它模块-->
<modules>
<module>../ssm_controller</module>
<module>../ssm_service</module>
<module>../ssm_dao</module>
<module>../ssm_pojo</module>
</modules>
<!--自定义属性,一般写在环境中-->
<properties>
<spring.version>5.1.9.RELEASE</spring.version>
</properties>
<!--创建多环境,这样可以调用不同环境来进行不同配置-->
<profiles>
<!--生产环境-->
<profile>
<id>pro_env</id>
<properties>
<jdbc.url>jdbc:mysql://localhost:3306/ssm</jdbc.url>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.username>root</jdbc.username>
<jdbc.password>love5460</jdbc.password>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!--开发环境-->
<profile>
<id>dep_env</id>
<properties>
<jdbc.url>jdbc:mysql://localhost:3306/ssm</jdbc.url>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.username>root</jdbc.username>
<jdbc.password>love5460</jdbc.password>
</properties>
</profile>
</profiles>
<!--声明此处进行依赖管理-->
<dependencyManagement>
<!--具体的依赖-->
<dependencies>
<!--添加自己的工程模块依赖-->
<dependency>
<groupId>com.lzb</groupId>
<artifactId>ssm_pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lzb</groupId>
<artifactId>ssm_dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lzb</groupId>
<artifactId>ssm_service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--spring环境-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!--mybatis环境-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.3</version>
</dependency>
<!--mysql环境-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!--spring整合jdbc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--spring整合mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.3</version>
</dependency>
<!--druid连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>
<!--分页插件坐标-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<!--springmvc环境-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--jackson相关坐标3个-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
<!--servlet环境-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--其他组件-->
<!--junit单元测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!--spring整合junit-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<!--设置插件-->
<plugins>
<!--具体的插件配置-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>80</port>
<path>/</path>
</configuration>
</plugin>
<!--跳过部分测试-->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/UserServiceTest*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<!--配置资源路径,就是用来寻找jdbc.properties等文件的-->
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
<!--发布配置管理,上传私服,使用的是nexus-->
<distributionManagement>
<repository>
<id>lzb-release</id>
<url>http://localhost:8081/repository/lzb-release/</url>
</repository>
<snapshotRepository>
<id>lzb-snapshots</id>
<url>http://localhost:8081/repository/lzb-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
service模块的pom文件
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!--添加夫工程的依赖,注意relativePath路径-->
<parent>
<groupId>com.lzb</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../ssm/pom.xml</relativePath>
</parent>
<!--定义自己包名,一般是自动生成的,controller层用war,其余的默认为jar-->
<modelVersion>4.0.0</modelVersion>
<artifactId>ssm_service</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<!--具体依赖,有dao的依赖,以及一些别人提供的依赖,所有依赖版本由父工程pom文件
控制,达到版本一致,所以不需要写version-->
<dependencies>
<dependency>
<groupId>com.lzb</groupId>
<artifactId>ssm_dao</artifactId>
</dependency>
<!--spring环境-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<!--其他组件-->
<!--junit单元测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!--spring整合junit-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>
</project>
版权声明:本文为XiaoZe1186516334原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。