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? 提供了强大的功能函数解决浏览器 ...
随机推荐
- shiro框架学习-6-Shiro内置的Filter过滤器及数据加解密
1. shiro的核心过滤器定义在枚举类DefaultFilter 中,一共有11个 ,配置哪个路径对应哪个拦截器进行处理 // // Source code recreated from a .c ...
- sql 导入文件
zai SQLQuery4.sql 文件中 --BULK INSERT Table_1 from 'D:\aaaa#azzz.txt' with(fieldterminator=',',rowterm ...
- 2-sat基础详解
(大量引用<2-SAT解法浅析 -by 华中师大一附中 赵爽><由对称性解2-SAT问题> Great_Influence关于P4782 [模板]2-SAT 问题的题解.在此对 ...
- 如何在matalb图像上添加公式符号
方法: legend({'$\sigma(t)$'},'interpreter','latex') 效果如下:
- 堤堤云海外IDC
http://www.ddyidc.com 堤堤云网络全球互联 堤堤云网络致力为客户提供优质的海外服务器租用服务,各种专线解决方案. 产品分类:服务器租用.IP租用.托管.专线传输.防御.优质回国CN ...
- 使用oracle删除表中重复记录
(1)使用用rowid方法 查询重复数据:select * from person a where rowid !=(select max(rowid) from person b where a.c ...
- 利用python的图像分块与拼接
import os import matplotlib.pyplot as plt import cv2 import numpy as np def divide_img(img_path, img ...
- R实现pm2.5地图数据展示
使用rvest包抓取pm2.5静态页面数据,使用leafletCN包实现pm2.5数据的地图展示,代码如下所示: library(rvest) library(leafletCN) Sys.setlo ...
- 深入理解android的UI更新机制
深入理解android的UI更新机制 由问题开始: 如何更新android UI? 可以通过如下方法: 在主线程里直接操作UI控件. handler.post(Runnable) runOnUiThr ...
- C# hook WndProc
在当前窗口里重载WndProc,只能捕获到当前WinForm窗口的消息 protected override void WndProc(ref Message m) { if (m.Msg == WM ...