1: Mavne的安装
2:Mavne的配置
conf/setting.xml中的本地仓库的配置。 默认仓库的路径: C:\Documents and Settings\当前登录系统的用户名\.m2\repository
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository --> <localRepository>D:/apache-maven-repository</localRepository>
3:MyEclipse中配置Maven MyEclipse---->Maven4MyEclipse--->Maven 配置 Installations:配置本地Maven的目录。 User Setting中配置setting.xml的位置与本地仓库的位置。4:Maven的常用命令
compile:编译工程 test: 对工程中的类进行测试 package:将工程打包 install:将打好的的包,安装到仓库中 deploy:将工程部署到私服或者容器中。 命令用先后顺序。5:在MyEclipse中新建maven项目。
6:Mavne中的“约定优于配置” A:项目的结构 源文件夹。 src/main/java :放java类。 src/main/resources : 放工程的配置文件。 src/test/java :放测试类 src/test/resources: :放测试的配置文件。 B:maven的配置文件. pom.xml groupId: Maven工程的标识号(分组号) artifactId Maven工程的名称 version 版本。
//加载相应的依赖包 <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> </dependency>
5:Maven的常用命令
clean -X:可以输出命令过程中具体的执行操作。 出现错误: A:重新下载插件目录,让Mavne重新下载 B:pom.xml配置插件的属性,让其插件跳过一些步骤。6:数据库驱动的下载:
中央仓库无法下载的jar包。 手工加载 A:建文件夹的方式安装jar
<dependency> <groupId>oracle.jdbc</groupId> <artifactId>driver</artifactId> <version>10.1</version> </dependency>仓库的文件夹的目录就应该为 orace/jdbc/driver/10.1/driver-10.1.jar B:maven的命令来安装jar mvn install:install-file -DgroupId=包名 -DartifactId=项目名 -Dversion=版本号 -Dpackaging=jar -Dfile=jar文件所在路径7:maven中依赖的传递 主要是通过dependency中的scope来决定。
test: 依赖的作用范围为测试期间。而且不会传递依赖 compile: 依赖的作用范围为编译期间。而且会传递依赖 runtime: 编译期间不需要,运行期间需要。而且会传递依赖(jdbc驱动) provided: 依赖的作用范围为供应商提供。而且不会传递依赖(servlet-api与jsp-api)8:Maven中依赖冲突jar的解决
1:Maven中按照引用jar的路径长短来比较。相同的jar不同版本,在各自的工程中存在。 导入引用最短的路径。 2:如果路径相同的情况下:引入最先引用dependency中存在的jar 3:如果需要自已自定义引用的jar包。 A:重新使用dependency来引入jar
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.2</version> </dependency>
B:通过排除的方式排除不需要的jar
<dependency> <groupId>com.dfrz</groupId> <artifactId>maven_04</artifactId> <version>0.0.1-SNAPSHOT</version>引用maven_04这个jar包,排除junit的依赖。
<exclusions> <exclusion> <groupId>junit</groupId> <artifactId>junit</artifactId> </exclusion> </exclusions> </dependency>
转载于:https://www.cnblogs.com/Arvin-9/p/4664167.html