Maven - Maven3实战学习笔记(1)Maven使用入门
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使用入门的更多相关文章
- Maven - Maven3实战学习笔记(2)坐标和依赖
1.maven坐标元素 maven坐标元素包括:groupId.artifactId.version.packaging.classifier. classifier:定义输出的附属构件.groupI ...
- Maven - Maven3实战学习笔记(3)使用maven构建Web应用
1.jetty-maven-plugin自动化测试Web应用工具 <plugin> <groupId>org.mortbay.jetty</groupId> < ...
- maven权威指南学习笔记(三)——一个简单的maven项目
目标: 对构建生命周期 (build lifecycle),Maven仓库 (repositories),依赖管理 (dependency management)和项目对象模型 (Project O ...
- maven 一个简单项目 —— maven权威指南学习笔记(三)
目标: 对构建生命周期 (build lifecycle),Maven仓库 (repositories),依赖管理 (dependency management)和项目对象模型 (Project O ...
- MAVEN学习笔记之Maven插件的应用(4)
MAVEN学习笔记之Maven插件的应用(4) <build> <pluginManagement> <plugins> <plugin> <gr ...
- MAVEN学习笔记之Maven生命周期和插件简介(3)
MAVEN学习笔记之Maven生命周期和插件简介(3) clean compile site三套生命周期相互独立. clean pre-clean 执行清理前的工作 clean 清理上一次构建生成的所 ...
- Redis in Action : Redis 实战学习笔记
1 1 1 Redis in Action : Redis 实战学习笔记 1 http://redis.io/ https://github.com/antirez/redis https://ww ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- jQuery学习笔记 - 基础知识扫盲入门篇
jQuery学习笔记 - 基础知识扫盲入门篇 2013-06-16 18:42 by 全新时代, 11 阅读, 0 评论, 收藏, 编辑 1.为什么要使用jQuery? 提供了强大的功能函数解决浏览器 ...
随机推荐
- 科普TPF知识
https://tieba.baidu.com/p/4926092734?see_lz=1&pn=1 707680700 https://tieba.baidu.com/p/492609273 ...
- jquery滚动到指定位置
利用jquery实现页面可视区滚动到指定位置.直接上代码 //滚动到指定位置 function scrollTo(element,speed) { if(!speed){ speed = 300; } ...
- 洛谷 P2473 [SCOI2008]奖励关 ( 期望DP )
题目链接 题意 : 中文题.点链接 分析 : 第一道有关概率期望的DP 有个大部分情况下通用的结论 概率正推.期望反推 原因不明.其实是没有查到较好的解释 这题由于有一些取物品的先决条件在这里 而且观 ...
- HDU 6444 Neko's loop ( 2018 CCPC 网络赛 && 裴蜀定理 && 线段树 )
题目链接 题意 : 给出一个 n 个元素的环.可以任意选择起点.选完起点后.可以行走 m 步.每次前进 k 个单位.所走到的点将产生正或负贡献.问你一开始得准备多少才能使得初始资金加上在环上获取最大利 ...
- 【LOJ2604】「NOIP2012」开车旅行
[题目链接] [点击打开链接] [题目大意] 从西到东的坐标轴\([1,n]\)上有\(n\)个海拔互不相同的城市,每两个城市之间的距离定义为\(dis(i,j)=|h_i-h_j|\) 小\(A\) ...
- Linux iptables 防火墙设置
1.查看防火墙iptables -L -niptablesb -L -n --line-number 显示规则行号看到 INPUT ACCEPT, FORWARD ACCEPT , OUTPUT A ...
- java 判断Map集合中包含指定的键名,则返回true,否则返回false。
public static void main(String[] args) { Map map = new HashMap(); //定义Map对象 map.put("apple" ...
- mongo 是什么
一.概述1.MongoDB是什么?用一句话总结MongoDB是一款为web应用程序和互联网基础设施设计的数据库管理系统.没错MongoDB就是数据库,是NoSQL类型的数据库 2.为什么要使用Mong ...
- TensorFlow线性回归
目录 数据可视化 梯度下降 结果可视化 数据可视化 import numpy as np import tensorflow as tf import matplotlib.pyplot as plt ...
- 方法二:Excel 2016 VBA工程密码破解
将你要破解的Excel文件关闭,切记一定要关闭呀!然后新建一个Excel文件 打开新建的这个Excel,按下alt+F11,打开vb界面,新建一个模块,如图所示 将代码复制到这个模块中,代码如下:Pr ...