SSM框架配合Maven时,pom.xml配置详解。

版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29519041/article/details/84994072

这篇博客针对我这样的小白。

一. pom.xml有什么用?: 

我们知道maven(什么是maven请移步https://www.cnblogs.com/whgk/p/7112560.html

可以给我们管理jar包和其他资源(jar包:别人写好的轮子,我们负责调用)

那pom.xml里面就书写了,告诉了maven,当前项目需要用到哪些轮子

从pom.xml中我们可以看见我们只需要书写我们需要的轮子的:

1.属于哪个组织写的(<groupId>

2.写的啥(<artifactId>

3. 需要哪个版本(<version>

4.在你的项目中作用范围(<scope>)比如写test那就是这个jar包只在test那个包下使用,写provided那就是开发阶段使用,项目部署在tomcat上后,tomcat是没有被provided修饰过的jar包的。当然是为了节约服务器资源,不需要的jar包就不传。

ps:至于maven去哪里找资源,就是他的事了,你只需要你说明你要啥。当然你可以继续了解本地仓库与远程仓库。

然后可以看见一个jar包就如下配置:

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

一个SSM框架下的Maven项目的pom.xml配置:

<?xml version="1.0" encoding="UTF-8"?><!--指定xml文档的版本和编码方式-->
<!--project是所有pom.xml的根元素,
它还声明了一些POM相关的命名空间及xsd元素,
虽然这些属性不是必须的,
但使用这些属性能够让第三方工具
(如:IDE中的xml编辑器)帮助我们快速编辑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">
    <!--指定了当前POM模型的版本,对于maven2及maven3来说,它只能是4.0.0。
    这段代码中最重要的是包含groupId,artifactId和version的三行。
    这三个元素定义了一个项目基本的坐标,在maven的世界,
    任何的jar,pom或者war都是以基于这些基本的坐标进行区分的。-->
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.yun</groupId><!--填写你的组织名例如-->
    <artifactId>test</artifactId><!--项目名字-->
    <version>1.0-SNAPSHOT</version><!--项目的版本 snapshot为快照意思,代表当前为测试版,
                                        开发版,相对的为release,意味发行版本,代表稳定版-->
    <packaging>war</packaging><!--问你项目需要打成什么包?pom jar war?一般javaWeb项目填war-->
    <name>ssm Maven Webapp</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
    <dependencies>
        <!--引入junit,做单元测试用,@Test注解需要它-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <!--set get方法使用注解开发时需要它-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.4</version>
            <scope>provided</scope>
        </dependency>
        <!--引入servlet-api 比如说HttpServletRequest和HttpServletResponse等对象,这些对象都要靠这个jar包才能使用-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <!--jsp的依赖-->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
        <!--引入jstl,书写jstl时要用到-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!--引入mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>
        <!--引入mybatis-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.8</version>
        </dependency>
        <!--引入spring-->
        <!--提供对AspectJ的支持-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <!--这个jar 文件包含在应用中使用Spring 的AOP 特性时所需的类和源码级元数据支持。使用基于AOP 的Spring特性,
        如声明型事务管理(Declarative Transaction Management),也要在应用里包含这个jar包。-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <!--这个jar 文件包含对Spring 对JDBC 数据访问进行封装的所有类。-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <!--基于tx的事务管理需要-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <!--这个jar 文件是所有应用都要用到的,它包含访问配置文件、
        创建和管理bean 以及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。
        如果应用只需基本的IoC/DI 支持,引入spring-core.jar 及spring-beans.jar 文件就可以了。
        外部依赖spring-core-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <!--这个jar 文件包含支持UI模版(Velocity,FreeMarker,JasperReports),
        邮件服务,脚本服务(JRuby),缓存Cache(EHCache),
        任务计划Scheduling(uartz)方面的类。
        外部依赖spring-context, (spring-jdbc, Velocity, FreeMarker, JasperReports, BSH, Groovy, JRuby, Quartz, EHCache)-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <!--spring表达式语言-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <!--基础web功能,如文件上传-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <!--spring测试,提供junit与mock测试功能-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.2.4.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <!--引入springmvc,mvc实现-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

        <!--fastjson,把对象和json格式互转换时需要用到-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.49</version>
        </dependency>
        <!--ueditor,一个富文本编辑器-->
        <dependency>
            <groupId>com.gitee.qdbp.thirdparty</groupId>
            <artifactId>ueditor</artifactId>
            <version>1.4.3.3</version>
        </dependency>
        <!--jackson,把对象和json格式互转换时需要用到-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.7</version>
        </dependency>
        <!--dbcp,还记得数据库连接池么??还有C3P0,druid这些-->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <!--jedis,Jedis是Redis官方推荐的Java连接开发工具。-->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.8.2</version>
        </dependency>
        <!--commons-lang3-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <!--commons-fileupload-->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.3</version>
        </dependency>
        <!--引入log4j,生成日志需要这个,log for java ,4是 for的近音-->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
        </dependency>

        <!--引入mybatis和spring-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>

    </dependencies>
    <build>
        <finalName>ssm</finalName><!--该项目名的时候改这里-->
    </build>
</project>

参考博客:

http://blog.sina.com.cn/s/blog_534f69a001010lpv.html

https://blog.csdn.net/u011781521/article/details/53760225

https://www.cnblogs.com/whgk/p/7112560.html

https://blog.csdn.net/qq277798882/article/details/53790199

https://blog.csdn.net/qq277798882/article/details/53790199

猜你喜欢

转载自blog.csdn.net/qq_29519041/article/details/84994072
今日推荐