##简介 Maven是基于POM(Project Object Model)的项目管理工具,可以管理项目的构建、发布。
##主要特点
简化编译(build)过程统一开发规范与工具统一管理jar包##好处
管理多个.jar文件。在开发Java应用时常常需要使用大量的第三方开发包,这些开发包大多数是.jar 的形式提供,比如使用spring 框架,通常的用法是下载这些.jar 文件,然后添加到Java下面中。部署时也要一些打包这些.jar 文件。使用Maven,在POM 中描述所需引用(依赖的)的库,在编译,发布,部署时Maven会自动下载或本地寻找所需库文件。因此使用Maven通常需要有网络连接。管理Java项目的依赖和版本,Java依赖的库有不同的版本,提供在POM文件指定所引用库的版本号,Maven自动帮助管理这些依赖关系及其版本。使用标准的项目结构,开发和测试人员可以使用标准的项目目录结构。Maven定义了项目开发的几个标准步骤:编译,发布,单元测试及部署以帮助项目开发。##安装
安装JDK,配置JAVA_HOME下载Maven解压,并把解压的bin目录加入PATH测试 mvn -vMAVEN_HOME为maven安装目录,如D:\apache-maven-3.6.3。 在path里增加mvn命令所在目录,如%MAVEN_HOME%\bin。
在maven配置文件(%MAVEN_HOME%\conf\settings.xml)里增加:
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url> http://maven.aliyun.com/nexus/content/groups/public/ </url> <mirrorOf>central</mirrorOf> </mirror> </mirrors>在maven配置文件里增加:
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>D:\maven_repos</localRepository> <!-- interactiveMode | This will determine whether maven prompts you when it needs input. If set to false, | maven will use a sensible default value, perhaps based on some other setting, for | the parameter in question. | | Default: true <interactiveMode>true</interactiveMode> -->配置maven本地库在D:\maven_repos目录下。
测试:
mvn help:system如果本地库目录下有文件了就是成功配置了。
在IntelliJ的File Settings里,配置如下: 如果想默认都这样设置,需要在IntelliJ - File - Other Settings - Settings for New Projects… 里同样这样设置。
最好使用阿里的代理,速度会快很多。
mvn archetype:generate###打包
mvn package###运行
java -cp .\HelloWorld-1.0-SNAPSHOT.jar com.pstreets.mavendemo.App###导入到workspace File->Import->Maven->Existing Maven Projects
参考: http://www.cnblogs.com/hongwz/p/5456616.html https://www.jianshu.com/p/1782feee6eff
