美文网首页
maven学习笔记(三):maven常用命令及自动化创建项目

maven学习笔记(三):maven常用命令及自动化创建项目

作者: 棒打耗子v5 | 来源:发表于2018-09-14 17:03 被阅读0次

1、比较常用的
常用命令:compile 编译

                  package 打包

                  install 将项目打成jar包放入本地仓库

                 clean  删除target

2、创建maven项目

项目的构建:

       使用maven构建web 项目,首先进入项目的根目录。

       使用命令:mvn archetype:generate -DgroupId=组织名 -DartifactId=项目名_模块名 -Dversion=版本号 -Dpackage=代码所存在的包名

       例如:mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DarchetypeArtifactId=maven-archetype-webapp -Dpackage=com.xxx.java

      初次建立项目会需要去中央仓库去下载一些相关的依赖包。会花比较长的时间。下载到本地仓库之后就不需要再次下载了。

      maven默认的中央仓库是英国,所以因为国内访问外网不方便的原因可能导致下载失败或者及其的慢,所以我们可以把中央仓库改为国内的。

     在/User/xxx/maven/apache-maven-3.5.4/conf/settings.xml中,有配置镜像地址的示例,


<!-- 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>

  </mirrors>

      <name>Human Readable Name for this Mirror.</name>

      <url>http://my.repository.com/repo/path</url>

    </mirror>

    -->

被注释的部分就是配置镜像地址方式,将注释去掉,配置修改为如下:

其中的url就是国内的中央仓库地址,其中包含了大部分开源的第三方库和框架。

安装jar包到本地仓库命令

mvn install:install-file -Dfile=commons-httpclients-3.1.jar  -DgroupId=commons-httpclient -DartifactId=commons-httpclient -Dversion=3.1 -Dpackaging=jar

相关文章

网友评论

      本文标题:maven学习笔记(三):maven常用命令及自动化创建项目

      本文链接:https://www.haomeiwen.com/subject/smoogftx.html