1、maven安装

1》http://maven.apache.org/download.cgi下载apache-maven-3.6.1

2》解压缩安装包到指定的文件夹,如C:\fyliu\software\apache-maven-3.6.1

3》配置maven用户环境变量MAVEN_HOME

4》设置Http访问代理

5》配置本地库路径

6》配置镜像

<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>

7》配置用户范围setting.xml

2、maven的pom.xml

<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.lfy.cn</groupId>
<artifactId>helloworld</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>maven helloworld project</name>
</project>
说明:
project元素:是所有pom.xml的根元素。
modelVersion:指定当前pom模型的版本,maven2、maven3只能是4.0.0
groupId:定义项目属于哪个组
artifactId:定义当前maven项目在组中的唯一ID
version:指定了项目当前的版本
groupId、artifactId、version:定义了一个项目的基本坐标。
#clean告诉maven清理输出目录target/
#compile告诉maven编译项目主代码
mvn clean compile
<!-- scope:表示依赖范围,默认为compile,表示该依赖对主代码、测试代码都有效。
test表示该依赖只对测试有效,即测试代码中import junit没问题,但是如果
我们在主代码中import junit,就会造成编译错误。-->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

3、打包和运行

#默认打包类型为jar
#package会执行编译、测试、打包的过程
mvn clean package

4、打包和安装

#install将会执行编译、测试、打包、安装到本地库
mvn clean install

5、为了使maven打包的jar能够有main方法的入口信息,在pom.xml中添加如下插件

    <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.lfy.mvnbook.helloworld.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

6、使用Archetype生成项目骨架

  我们也可以开发自己的Archetype项目以生成自己的项目骨架。选择不同的Archetype项目模板,可以生成快速启动项目、Webapp项目。

C:\fyliu\lfyTemp\mvnProject\mvn-archetype-generate>mvn archetype:generate
[INFO] Scanning for projects...
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/o
rg/apache/maven/plugins/maven-archetype-plugin/maven-metadata.xml
...
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/or
g/apache/maven/plugins/maven-archetype-plugin/3.1./maven-archetype-plugin-3.1.
.jar ( kB at kB/s)
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM)
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.1.:generate (default-cli) > generate-source
s @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.1.:generate (default-cli) < generate-source
s @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.1.:generate (default-cli) @ standalone-pom
---
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/o
rg/apache/maven/archetype/archetype-catalog/3.1./archetype-catalog-3.1..pom
...
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/or
g/apache/ant/ant/1.8./ant-1.8..jar (1.5 MB at kB/s)
[INFO] Generating project in Interactive mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.
archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archety
pe which contains a sample archetype.)
: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An arche
type which contains a simplifed sample J2EE application.)
: internal -> org.apache.maven.archetypes:maven-archetype-plugin (An archetype
which contains a sample Maven plugin.)
: internal -> org.apache.maven.archetypes:maven-archetype-plugin-site (An arche
type which contains a sample Maven plugin site.
This archetype can be layered upon an existing Maven plugin project.)
: internal -> org.apache.maven.archetypes:maven-archetype-portlet (An archetype
which contains a sample JSR- Portlet.)
: internal -> org.apache.maven.archetypes:maven-archetype-profiles ()
: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An archet
ype which contains a sample Maven project.)
: internal -> org.apache.maven.archetypes:maven-archetype-site (An archetype wh
ich contains a sample Maven site which demonstrates
some of the supported document types like APT, XDoc, and FML and demonstra
tes how
to i18n your site. This archetype can be layered upon an existing Maven pr
oject.)
: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (An arche
type which contains a sample Maven site.)
: internal -> org.apache.maven.archetypes:maven-archetype-webapp (An archetype
which contains a sample Maven Webapp project.)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive co
ntains): 7:
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/o
rg/apache/maven/archetypes/maven-archetype-bundles//maven-archetype-bundles-.p
om
...
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/or
g/apache/maven/archetype/maven-archetype/2.0-alpha-/maven-archetype-2.0-alpha-
.pom (8.7 kB at kB/s)
Define value for property 'groupId': com.lfy.mvnbook
Define value for property 'artifactId': hello-world
Define value for property 'version' 1.0-SNAPSHOT: :
Define value for property 'package' com.lfy.mvnbook: : com.lfy.mvnbook.helloworl
d
Confirm properties configuration:
groupId: com.lfy.mvnbook
artifactId: hello-world
version: 1.0-SNAPSHOT
package: com.lfy.mvnbook.helloworld
Y: : Y
[INFO] -------------------------------------------------------------------------
---
[INFO] Using following parameters for creating project from Old (.x) Archetype:
maven-archetype-quickstart:1.1
[INFO] -------------------------------------------------------------------------
---
[INFO] Parameter: basedir, Value: C:\fyliu\lfyTemp\mvnProject\mvn-archetype-gene
rate
[INFO] Parameter: package, Value: com.lfy.mvnbook.helloworld
[INFO] Parameter: groupId, Value: com.lfy.mvnbook
[INFO] Parameter: artifactId, Value: hello-world
[INFO] Parameter: packageName, Value: com.lfy.mvnbook.helloworld
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (.x) Archetype in dir: C:\fyliu\lfyTemp\mvnProj
ect\mvn-archetype-generate\hello-world
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: : min
[INFO] Finished at: --15T00::+:
[INFO] ------------------------------------------------------------------------ C:\fyliu\lfyTemp\mvnProject\mvn-archetype-generate>

7、使用Eclipse就可以导入我们上面使用骨架语句创建的项目了

8、 可以使用Eclipse创建maven快速启动项目、Webapp项目

9、Eclipse中运行mvn命令

可以在pom.xml上右键,Run as。如果列表中的命令不能一次满足我们的mvn执行需求,可以选择Maven build...自定义maven命令,如在Goals中输入clean test。

Maven - Maven3实战学习笔记(1)Maven使用入门的更多相关文章

  1. Maven - Maven3实战学习笔记(2)坐标和依赖

    1.maven坐标元素 maven坐标元素包括:groupId.artifactId.version.packaging.classifier. classifier:定义输出的附属构件.groupI ...

  2. Maven - Maven3实战学习笔记(3)使用maven构建Web应用

    1.jetty-maven-plugin自动化测试Web应用工具 <plugin> <groupId>org.mortbay.jetty</groupId> < ...

  3. maven权威指南学习笔记(三)——一个简单的maven项目

    目标: 对构建生命周期 (build  lifecycle),Maven仓库 (repositories),依赖管理 (dependency management)和项目对象模型 (Project O ...

  4. maven 一个简单项目 —— maven权威指南学习笔记(三)

    目标: 对构建生命周期 (build  lifecycle),Maven仓库 (repositories),依赖管理 (dependency management)和项目对象模型 (Project O ...

  5. MAVEN学习笔记之Maven插件的应用(4)

    MAVEN学习笔记之Maven插件的应用(4) <build> <pluginManagement> <plugins> <plugin> <gr ...

  6. MAVEN学习笔记之Maven生命周期和插件简介(3)

    MAVEN学习笔记之Maven生命周期和插件简介(3) clean compile site三套生命周期相互独立. clean pre-clean 执行清理前的工作 clean 清理上一次构建生成的所 ...

  7. Redis in Action : Redis 实战学习笔记

    1 1 1 Redis in Action : Redis  实战学习笔记 1 http://redis.io/ https://github.com/antirez/redis https://ww ...

  8. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  9. jQuery学习笔记 - 基础知识扫盲入门篇

    jQuery学习笔记 - 基础知识扫盲入门篇 2013-06-16 18:42 by 全新时代, 11 阅读, 0 评论, 收藏, 编辑 1.为什么要使用jQuery? 提供了强大的功能函数解决浏览器 ...

随机推荐

  1. getch和getchar的区别

    造冰箱的大熊猫@cnblogs 2018/11/30 1.getc() 头文件:stdio.h 函数声明:int getc ( FILE * stream ); 功能: - 返回流(stream)当前 ...

  2. Springboot 使用Jedis

    Springboot 使用Jedis 依赖 <dependency> <groupId>org.springframework.boot</groupId> < ...

  3. 【Vue】input textarea自动滚动到输入处

    由于我这里要把接口返回的日志不断地新增到textarea里,想实现自动滚动日志的效果. 1.首先定一个textarea类型的input组件 <el-input id="textarea ...

  4. vim文件编辑器

    Vim 是 Vi 的增强版(在 Vi 的基础上增加了正则表达式的查找.多窗口的编辑等功能),使用 Vim 进行程序开发会更加方便. 想深入了解 Vi 和 Vim 的区别,可以在 Vim 命令模式下输入 ...

  5. 【Python】爬虫汇总

    主要流程: 获取url下载网页从网页中找寻自己需要的保存(解析+输出)主要概念URL:分大小写统一资源定位符,对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联 ...

  6. crm 项目的部署

    发布CRM你将使用以下软件 nginx uWSGI CentOS7 CRM项目文件 virtualenv supervisor WSGI.uWSGI python web服务器开发使用WSGI协议(W ...

  7. 剑指offer32----之字形打印一颗二叉树

    题目 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 思路 在这里我们如果单纯的使用队列去弄的话,会很 ...

  8. jQuery Validate 验证成功时的提示信息

    大多数时候我们使用validate进行前台验证的时候,都是验证错误的时候给出提示信息,最近在做一个项目的时候,想这验证成功后给出一个验证成功的提示.于是在网上找了一些资料. <!doctype ...

  9. linux查询端口被哪个程序使用了

    使用如下命令查询8000端口被哪个程序使用 netstat -tunlp|

  10. Boston House Price with Scikit-Learn

    Boston House Price with Scikit-Learn Data Description >>> from sklearn.datasets import load ...