第一讲:

maven
maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。
maven安装与下载:
、确定jdk已经安装并且配置
、安装maven
、配置maven环境变量:M2_HOME D:\maven\apache-maven-3.3. (就是maven的安装目录) HelloWorld的实现
modelVersion:POM模型版本4..0固定
groupId:一般指某个公司或者某个组织的某个项目,比如org.springframework
artifactId:一般指某个具体项目的某个具体模块,比如spring-context
Version:项目的版本
Maven常见命令:
complie 编译
clean 清空
test 测试
package 打包
install 将项目安装到本地仓库
Mvn远程仓库地址:http://mvnrepository.com/

第二讲,我的实践:

使用idea创建helloWorld的maven项目:

Mvn远程仓库地址:http://mvnrepository.com/ 这个很重要,我们的需要什么jar包都可以在上面搜寻坐标
idea的时候文件夹的颜色标识这个也重要,不然可能无法new出想要的file 然后就是测试各个maven命令:

第三讲:

maven仓库的概念:

Maven远程仓库配置文件:
$M2_HOME/lib/maven-model-builder-3.3.9jar
下的文件:org/apache/maven/model/pom-4.0.0.xml

-<repositories>

-<repository>

<id>central</id>

<name>Central Repository</name>

<url>https://repo.maven.apache.org/maven2</url>

<layout>default</layout>

-<snapshots>

<enabled>false</enabled>

</snapshots>

</repository>

</repositories>

maven依赖:
我们可以将一个项目install到本地仓库,然后本地其他项目引用这个项目,就是引用这个项目的下标,如:
<dependencies>
<dependency>
<groupId>com.java1234.user</groupId>
<artifactId>user-dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
我们做个例子:
使用maven创建ssm项目的各个模块并且成功运行:
关键代码:

其实没有什么关键代码,就是ssm的整合搭建

依赖的特性:

  最短路径原则和最先声明原则。就是如果A项目中引用了B和C项目,B中间接引用了F,C直接引用了F,那么A中引用F依赖是通过C来达到的,就近原则。当两边路径相等的时候,哪个项目被先引用就使用哪个项目得到依赖。

第四讲:

maven的聚合与继承:
聚合:
新的maven项目中,这样聚合其他项目:

<modules>
<module>../user-dao</module>
<module>../user-service</module>
</modules>
注意该项目中package只能为pom:
<packaging>pom</packaging>

作用:方便统一管理

继承:
继承实现:
新建父项目,然后在子项目坐标前加上继承描述:

<parent>
<groupId>com.java1234.user</groupId>
<artifactId>user-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../user-parent/pom.xml</relativePath>
</parent>

relativePath一定要加上。

注意:一定要在子项目坐标前,然后就可以使用继承了。
方便版本版本管理与依赖管理
使用了继承子项目的groupId可以删掉了,默认使用的是父项目的groupId。默认状况下 version和packing也是继承父项目的,适当情况下可以省略不写。webapp项目注意packing不要省略,因为父项目一般是jar形式打包,webapp是war包
每个子项目中都有好多jar,它们可能太多的时候导致版本混乱,这样的话我们可以将这些依赖都假如到父类的dependency里面,然后子模块继承父模块可以省略子模块中的版本和scope。都使用父类的版本其他。

注意是放在dependencyManagement里面的dependencies里面添加依赖

<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>

可以在pom里面声明版本属性,然后在dependency里面应用它,我们常用来管理版本,使用方式看例子:

<properties>
<spring.version>4.3..RELEASE</spring.version>
<mybatis.version>3.4.</mybatis.version>
</properties> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>

我再父项目中装载了其他的子项目,便于管理。使用的idea,感觉还是新建一个项目和新建其他模块比较好一点。虽然效果好像差不多。

 

最终的项目各模块的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">
<modelVersion>4.0.</modelVersion> <parent>
<groupId>com.java1234.user</groupId>
<artifactId>user-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../user-parent/pom.xml</relativePath>
</parent> <artifactId>user-web</artifactId>
<packaging>war</packaging> <name>user-web Maven Webapp</name>
<url>http://maven.apache.org</url> <dependencies> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency> <dependency>
<groupId>com.java1234.user</groupId>
<artifactId>user-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency> </dependencies> <build>
<finalName>user-web</finalName>
</build> </project>

user-web的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">
<modelVersion>4.0.</modelVersion> <parent>
<groupId>com.java1234.user</groupId>
<artifactId>user-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../user-parent/pom.xml</relativePath>
</parent> <artifactId>user-dao</artifactId>
<packaging>jar</packaging> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</project>

user-dao的web

<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.</modelVersion> <parent>
<groupId>com.java1234.user</groupId>
<artifactId>user-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../user-parent/pom.xml</relativePath>
</parent> <artifactId>user-service</artifactId>
<packaging>jar</packaging> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency> <dependency>
<groupId>com.java1234.user</groupId>
<artifactId>user-dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency> </dependencies> </project>

user-service的web

<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.</modelVersion> <parent>
<groupId>com.java1234.user</groupId>
<artifactId>user-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../user-parent/pom.xml</relativePath>
</parent> <artifactId>user-service</artifactId>
<packaging>jar</packaging> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency> <dependency>
<groupId>com.java1234.user</groupId>
<artifactId>user-dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency> </dependencies> </project>

user-aggregator的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">
<modelVersion>4.0.</modelVersion> <groupId>com.java1234.user</groupId>
<artifactId>user-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging> <properties>
<spring.version>4.3..RELEASE</spring.version>
<mybatis.version>3.4.</mybatis.version>
</properties> <modules>
<module>../user-dao</module>
<module>../user-service</module>
<module>../user-web</module>
</modules> <dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.</version>
</dependency> <!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.</version>
</dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.</version>
</dependency> <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
</dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency> </dependencies> </dependencyManagement> </project>

user-parent的pom

 

java1234初学maven的更多相关文章

  1. 初学maven的一些配置

    初学Maven的一些配置 1.maven的安装 2.从官网下载3.6.1版本后,高级版本可能会出现不兼容 jdk1.8 3.配置maven 在 settings.xml <settings> ...

  2. 使用maven来管理java项目

    初学maven,简单总结一下学习心得,若有不对的地方,欢迎各位大神给我指正~ 总结分为6个部分 maven概述 maven安装 maven项目结构和创建方法 maven配置文件settings.xml ...

  3. Maven-004-使用 Nexus 搭建 maven 私服

    从去年至今,自己一直在学习自动化测试工具,想利用自动化工具尽可能的将重复的.关键的.耗时耗力的工作实现自动化,减轻日常测试工作,提升测试效率.在学习的过程中,将 maven 作为了项目开发管理工具,进 ...

  4. Maven-003-私人定制 maven archetype

    在使用 Maven 创建项目模块的时候,依据其默认的 archetype 模板,创建出的目录.及默认的单元测试工具为 JUnit 3.8.1,而且有些常用的资源文件目录.配置文件(例如:Log4J 的 ...

  5. Maven加依赖包

    对于初学maven的人来说刚开始会有个困惑,那就是怎么知道依赖的jar的groupId和atrifactId是什么, 比如要依赖mybatis,会在pom.xml中配置如下: <dependen ...

  6. Maven的JAR包仓库,不用再百度搜JAR包了!

    http://search.maven.org/ 今天初学Maven,发现Maven的中央仓库里差点儿什么jar都有...........还有各种版本号... 你值得拥有!

  7. maven配置环境

    今天初学maven,先学习一下如何在windows下面配置maven,当然你要先配置好jdk的环境. 第一步,上官网下载maven插件,网址是:点击打开链接 第二步,解压文件夹,放在某一个盘符下,我是 ...

  8. Maven Web项目出现org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException错误

    1. 问题描述 初学Maven,新建了一个基于Web骨架的Web项目,jar 包也导好了,作用域也设置正确了,Tomcat也正常运行了,可是就是说编译错误. 2. 问题原因 虽然我配置了Tomcat ...

  9. maven 报的一堆错

    今天初学maven,刚开始下载的是Apache-maven-3.6.2然后配置运行一个servlet,但是在pom.xml中写jar包坐标时一直报错显示红色,本地仓库和官网上的中央仓库都试过了就是依赖 ...

随机推荐

  1. 2014 ACM/ICPC Asia Regional Xi'an Online

    03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为 ...

  2. kali更新源

    原文链接:http://www.cnblogs.com/dunitian/p/4712852.html kali2.0官方下载地址: https://www.kali.org/downloads/ 可 ...

  3. ToolBar 修改边距

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android ...

  4. django表单

    一.主要内容 1.服务端获取HttpRequest信息        1)url相关信息        2)HttpRequest.META中包含的键值对        3)HttpRequest中用 ...

  5. 可靠UDP

    tcp为我们做了什么事情? 总得来说,tcp做了这几件事: 通过序列号和基于确认的超时重传机制,为上层提供了可靠的字节流服务: 通过滑动窗口.拥塞窗口提供了流量控制: 默认情况下,为了有效利用带宽,t ...

  6. 数据挖掘算法(一)C4.5

    统计了14天的气象数据D(指标包括outlook,temperature,humidity,windy),并已知这些天气是否打球(play).如果给出新一天的气象指标数据:sunny,cool,hig ...

  7. Java内存模型

    1. 概述 多任务和高并发是衡量一台计算机处理器的能力重要指标之一.一般衡量一个服务器性能的高低好坏,使用每秒事务处理数(Transactions Per Second,TPS)这个指标比较能说明问题 ...

  8. linux主要的发行版及其区别和联系

    1. 主要发行版 linux主要发行版有3类: (1).Debian (2).Slackware (3).Redhat (1)Debian Ubuntu 针对桌面和服务器 knopix 以安全著称 ( ...

  9. java list 简述

    list中可以添加任何对象,我可以给你举个例子:class Person{ .....}上面定义了一个Person类,下面看好如何使用ListPerson p1=new Person();Person ...

  10. oralce 密码长度

    Oracle 11G的新特性所致, Oracle 11G创建用户时缺省密码过期限制是180天, 如果超过180天用户密码未做修改则该用户无法登录. Oracle提示错误消息ORA-28001: the ...