博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Maven入门笔记
阅读量:5022 次
发布时间:2019-06-12

本文共 3677 字,大约阅读时间需要 12 分钟。

首先安装Maven,Maven的安装很简单,这里就不在说了。

先要确定把工程放在哪个路径下,创建一个文件夹并且在该文件夹下打开shell命令。可以先运行下面的命令,创建一个工程:

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

初次运行该命令会有些慢,因为maven需要下载一些最经常用到的artifacts到本地仓库(repository)。由于网络等原因,用户可能需要多次运行该命令,直到成功。

该命令会创建一个文件夹,名字就是所给的artifactid。文件夹结构如下,这是maven约定的:

455275-20160628175844609-184618012.png

工程的源代码放在src/main/java路径下,测试源代码放在src/test/java路径下。

pom.xml是整个工程配置的核心,样式如下:

455275-20160628175910109-1233946427.png

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来管理,首先要安装两个插件:

org.apache.maven.plugins
maven-compiler-plugin
3.1
1.8
1.8
maven-assembly-plugin
2.4.1
jar-with-dependencies
make-assembly
package
single

先说第一个插件maven-compiler-plugin。Maven默认的Jdk compiler是1.5,需要通过该插件改变编译器,否则一些新的特性,例如lamda表达式不能使用。

第二插件负责将整个工程、包括依赖的库打包,这样就可以通过spark-submit来在集群上运行了。

转载于:https://www.cnblogs.com/xianzhedeyu/p/5624362.html

你可能感兴趣的文章
关于git的认证方式
查看>>
字符串按照字典序排列
查看>>
IOS 开发调用打电话,发短信
查看>>
CI 框架中的日志处理 以及 404异常处理
查看>>
keepalived介绍
查看>>
css3 标签 background-size
查看>>
python itertools
查看>>
Linux内核调试技术——jprobe使用与实现
查看>>
样式、格式布局
查看>>
ubuntu设计文件权限
查看>>
Vue双向绑定原理详解
查看>>
Android基础总结(5)——数据存储,持久化技术
查看>>
关于DataSet事务处理以及SqlDataAdapter四种用法
查看>>
bootstrap
查看>>
http://lorempixel.com/ 可以快速产生假图
查看>>
工程经验总结之吹水"管理大境界"
查看>>
为什么JS动态生成的input标签在后台有时候没法获取到
查看>>
20189210 移动开发平台第六周作业
查看>>
java之hibernate之基于外键的双向一对一关联映射
查看>>
rxjs一句话描述一个操作符(1)
查看>>