Maven入门笔记
首先安装Maven,Maven的安装很简单,这里就不在说了。
先要确定把工程放在哪个路径下,创建一个文件夹并且在该文件夹下打开shell命令。可以先运行下面的命令,创建一个工程:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
初次运行该命令会有些慢,因为maven需要下载一些最经常用到的artifacts到本地仓库(repository)。由于网络等原因,用户可能需要多次运行该命令,直到成功。
该命令会创建一个文件夹,名字就是所给的artifactid。文件夹结构如下,这是maven约定的:

工程的源代码放在src/main/java路径下,测试源代码放在src/test/java路径下。
pom.xml是整个工程配置的核心,样式如下:

You executed the Maven goal archetype:generate, and passed in various parameters to that goal. The prefix archetype is the plugin that contains the goal. If you are familiar with Ant, you may conceive of this as similar to a task. This goal created a simple project based upon an archetype. Suffice it to say for now that a plugin is a collection of goals with a general common purpose. For example the jboss-maven-plugin, whose purpose is "deal with various jboss items".
build工程:
mvn package
Unlike the first command executed (archetype:generate) you may notice the second is simply a single word - package. Rather than a goal, this is a phase. A phase is a step in the build lifecycle, which is an ordered sequence of phases. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined. For example, if we execute the compile phase, the phases that actually get executed are:
validate
generate-sources
process-sources
generate-resources
process-resources
compile
用户可以通过下面的命令运行程序:
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
Maven的Phases:
- validate: validate the project is correct and all necessary information is available
- compile: compile the source code of the project
- test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
- package: take the compiled code and package it in its distributable format, such as a JAR.
- integration-test: process and deploy the package if necessary into an environment where integration tests can be run
- verify: run any checks to verify the package is valid and meets quality criteria
- install: install the package into the local repository, for use as a dependency in other projects locally
- deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
- clean: cleans up artifacts created by prior builds
- site: generates site documentation for this project
例如:
mvn clean dependency:copy-dependencies package
这个命令会清空工程、复制依赖并且build工程。
Spark的Java部分需要Maven来管理,首先要安装两个插件:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
先说第一个插件maven-compiler-plugin。Maven默认的Jdk compiler是1.5,需要通过该插件改变编译器,否则一些新的特性,例如lamda表达式不能使用。
第二插件负责将整个工程、包括依赖的库打包,这样就可以通过spark-submit来在集群上运行了。
Maven入门笔记的更多相关文章
- maven 入门
Apache Maven 入门篇 ( 上 ) 作者:George Ma 写这个 maven 的入门篇是因为之前在一个开发者会的动手实验中发现挺多人对于 maven 不是那么了解,所以就有了这个想法.这 ...
- SpringBoot入门笔记(一)、HelloWorld
本文是一篇SprintBoot学习入门笔记 1.打开Eclipse,版本为Oxygen 4.7.0 2.新建项目NewProject->MavenProject->Next->Nex ...
- Ruby小白入门笔记之 <Gemfile 文件>
因为初学Ruby,四处查资料无果,才来的贴出亲自试过的操作,覆盖整个个人入门笔记博客中,故所有的操作,都以最明了的方式阐述,当你创建完一个新的Rails应用后,你发现JAVA中我们可以编写maven聚 ...
- Maven入门详解
什么是Maven Maven,鼎鼎大名,在今天之前,我对于它一直是处于一种"只闻其名不见其人"的状态.之所以说"只闻其名",是因为Maven太有名了,它是Apa ...
- 每天成长一点---WEB前端学习入门笔记
WEB前端学习入门笔记 从今天开始,本人就要学习WEB前端了. 经过老师的建议,说到他每天都会记录下来新的知识点,每天都是在围绕着这些问题来度过,很有必要每天抽出半个小时来写一个知识总结,及时对一天工 ...
- ES6入门笔记
ES6入门笔记 02 Let&Const.md 增加了块级作用域. 常量 避免了变量提升 03 变量的解构赋值.md var [a, b, c] = [1, 2, 3]; var [[a,d] ...
- [Java入门笔记] 面向对象编程基础(二):方法详解
什么是方法? 简介 在上一篇的blog中,我们知道了方法是类中的一个组成部分,是类或对象的行为特征的抽象. 无论是从语法和功能上来看,方法都有点类似与函数.但是,方法与传统的函数还是有着不同之处: 在 ...
- React.js入门笔记
# React.js入门笔记 核心提示 这是本人学习react.js的第一篇入门笔记,估计也会是该系列涵盖内容最多的笔记,主要内容来自英文官方文档的快速上手部分和阮一峰博客教程.当然,还有我自己尝试的 ...
- Maven 入门 (2)—— 创建Maven项目
http://blog.csdn.net/kakashi8841/article/details/17427043 读这篇文章之前请先确保你成功安装了maven,如果你还没安装成功,请先看:Maven ...
随机推荐
- matlab 图片批量读取
1. 指定的路径 单目录data所有图片 file_path = '.\data\';% 图片目录路径 img_path_list = dir(strcat(file_path,'*.jpg'));% ...
- STL源代码分析 集装箱 stl_set.h
本文senlie原版的,转载请保留此地址:http://blog.csdn.net/zhengsenlie set ------------------------------------------ ...
- HDU1061-Rightmost Digit(高速功率模)
pid=1061">主题链接 题意:求n^n的个位数的值. 思路:高速幂求值 代码: #include <iostream> #include <cstdio> ...
- .NET(C#):浅谈程序集清单资源和RESX资源
原文:.NET(C#):浅谈程序集清单资源和RESX资源 目录 程序集清单资源 RESX资源文件 使用ResourceReader和ResourceSet解析二进制资源文件 使用ResourceM ...
- Unable to load Virtual engine
相关:GenyMotion自带VirtualBox 解决办法:首先确认genymotion及virtualBox正确安装,然后右键点击启动程序选属性,在兼容性里选以兼容模式运行,同时勾选以管理员身份运 ...
- UVA - 11324 The Largest Clique 强连通缩点+记忆化dp
题目要求一个最大的弱联通图. 首先对于原图进行强连通缩点,得到新图,这个新图呈链状,类似树结构. 对新图进行记忆化dp,求一条权值最长的链,每一个点的权值就是当前强连通分量点的个数. /* Tarja ...
- MVC中下拉框显示枚举项
原文:MVC中下拉框显示枚举项 本篇将通过3种方式,把枚举项上的自定义属性填充到下拉框: 1.通过控制器返回List<SelectListItem>类型给前台视图 2.通过为枚举类型属性打 ...
- MySQL分页实现
mysql> select pname from product; +--------+ | pname | +--------+ | 产品1 | | 产品2 | | 产品三 | +--- ...
- Ajax 实现无刷新页面
注意:如本文所用,在前面的文章库的数目可以在源代码中找到,我将指示在文本,其中链路,为了缩短制品的长度,阅读由此带来的不便.乞求被原谅. 评论文章 Ajax 实现无刷新页面.其原理.代码库.代码. 这 ...
- AspNetPager使用指南
一.AspNetPager支持两种方式分页: 一种是PostBack方式分页, 一种是通过Url来实现分页以及Url重写功能 二.AspNetPager支持各种数据绑定控件GridView.DataG ...