原文: http://www.cnblogs.com/yunwuzhan/p/5900311.html

https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Maven in 5 Minutes

Prerequisites

You must have an understanding of how to install software on your computer. If you do not know how to do this, please ask someone at your office, school, etc or pay someone to explain this to you. The Maven mailing lists are not the best place to ask for this advice.

Installation

Maven is a Java tool, so you must have Java installed in order to proceed.

First, download Maven and follow the installation instructions. After that, type the following in a terminal or in a command prompt:

  1. mvn --version

It should print out your installed version of Maven, for example:

  1. Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
  2. Maven home: D:\apache-maven-3.0.5\bin\..
  3. Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
  4. Java home: C:\Program Files\Java\jdk1.6.0_25\jre
  5. Default locale: nl_NL, platform encoding: Cp1252
  6. OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

Depending upon your network setup, you may require extra configuration. Check out the Guide to Configuring Maven if necessary.

If you are using Windows, you should look at Windows Prerequisites to ensure that you are prepared to use Maven on Windows.

Creating a Project

You will need somewhere for your project to reside, create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal:

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

If you have just installed Maven, it may take a while on the first run. This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository. You may also need to execute the command a couple of times before it succeeds. This is because the remote server may time out before your downloads are complete. Don't worry, there are ways to fix that.

You will notice that the generate goal created a directory with the same name given as the artifactId. Change into that directory.

  1. cd my-app

Under this directory you will notice the following standard project structure.

The src/main/java directory contains the project source code, the src/test/java directory contains the test source, and the pom.xml file is the project's Project Object Model, or POM.

The POM

The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively. This project's POM is:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.mycompany.app</groupId>
  5. <artifactId>my-app</artifactId>
  6. <version>1.0-SNAPSHOT</version>
  7. <packaging>jar</packaging>
  8. <name>Maven Quick Start Archetype</name>
  9. <url>http://maven.apache.org</url>
  10. <dependencies>
  11. <dependency>
  12. <groupId>junit</groupId>
  13. <artifactId>junit</artifactId>
  14. <version>4.8.2</version>
  15. <scope>test</scope>
  16. </dependency>
  17. </dependencies>
  18. </project>

What did I just do?

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 the Project

  1. mvn package

The command line will print out various actions, and end with the following:

  1. ...
  2. [INFO] ------------------------------------------------------------------------
  3. [INFO] BUILD SUCCESSFUL
  4. [INFO] ------------------------------------------------------------------------
  5. [INFO] Total time: 2 seconds
  6. [INFO] Finished at: Thu Jul 07 21:34:52 CEST 2011
  7. [INFO] Final Memory: 3M/6M
  8. [INFO] ------------------------------------------------------------------------

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:

  1. validate
  2. generate-sources
  3. process-sources
  4. generate-resources
  5. process-resources
  6. compile

You may test the newly compiled and packaged JAR with the following command:

  1. java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App

Which will print the quintessential:

  1. Hello World!

------------------------------------------------------------------------------------------------------------

Maven的安装与使用(ubuntu)

 

一.安装Maven

    1.下载Maven,http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz。

    2.解压,移动到相应文件夹:

        

        

    3.在/etc/profile中配置对应环境变量:

        

    4.mvn -v查看版本信息

        

二、Maven的使用及基本了解

    创建java项目:

    

    生成对应目录结构:

    

    1)Maven插件:mvn archetype:generate 就表示调用maven-archetype-plugin的generate目标,实际上就是让maven-archetype-plugin生成一个很简单的项目结构,ubuntu中Ctrl+H可查看隐藏文件,我的插件在/home/zhanyunwu/.m2/repository/org/apache/maven/plugins/maven-archetype-plugin目录下。我们同样可以使用其他插件:,在项目helloworld路径下运行,可发现在项目根目录下多了.classpath和.project文件,该插件使得项目可以导入到eclipse中去。还可以使用archetype插件选择其他模板建立如javaweb项目。

    2)Maven生命周期:除了自己调用插件,也可把相应插件目标与生命周期阶段绑定,来调用插件。例如 在helloworld路径下mvn package 会依次执行默认生命周期中直到包括 package 阶段前的所有阶段的插件目标。如下图,调用编译,测试,打包等插件。

    

【转】Maven的安装与使用(ubuntu)的更多相关文章

  1. Maven的安装与使用(ubuntu)

    一.安装Maven 1.下载Maven,http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-m ...

  2. Maven的安装、配置及使用入门

    Maven的安装.配置及使用入门 本书代码下载 大家可以从我的网站下载本书的代码:http://www.juvenxu.com/mvn-in-action/,也可以通过我的网站与我取得联系,欢迎大家与 ...

  3. MyEclipse对Maven的安装

    好记性不如烂笔头,记录一下. 操作系统:windows 7 MyEclipse2015 JDK1.7 maven的下载链接,点这里下载apache-maven-3.0.4-bin.tar.gz. 下载 ...

  4. 04.ubuntu下kvm 命令行安装64位ubuntu报"Couldn't find hvm kernel for Ubuntu tree."的问题

    1.安装ubuntu时使用的virt-install的配置: virt-install \ --name test4 \ --ram 1024 \ --disk path=/data/01_ubunt ...

  5. (二)Maven的安装与环境配置

    想要安装 Apache Maven在Windows 系统上, 需要下载 Maven 的 zip 文件,并将其解压到你想安装的目录,并配置 Windows 环境变量. 所需工具 : 1.JDK 2.Ma ...

  6. Maven的安装配置

    本文主要是针对mac os系统下maven的安装教程. 1.首先验证是否有jdk.java -version,没有需要手工安装 2.maven的下载地址:http://maven.apache.org ...

  7. maven本地安装jar包同时生成pom文件

    maven 本地安装jar包:mvn install:install-file -Dfile=本地路径/ojdbc12.jar -DgroupId=com.oracle -DartifactId=oj ...

  8. 64位win7硬盘安装64位ubuntu 13.04

    最近本来是准备通过升级的方式把ubuntu从12.04升级到12.10再升级到13.04的,但是升级到12.10之后,可能是因为某一步的操作不当,出现无法进入系统的情况.不过还好的是升级之前保存了主要 ...

  9. MyEclipse下Maven的安装配置

    Maven常用命令: •mvn archetype:generate :创建 Maven 项目 •mvn compile :编译源代码 •mvn test-compile :编译测试代码 •mvn t ...

随机推荐

  1. Java中多个线程交替循环执行

    有些时候面试官经常会问,两个线程怎么交替执行呀,如果是三个线程,又怎么交替执行呀,这种问题一般人还真不一定能回答上来.多线程这块如果理解的不好,学起来是很吃力的,更别说面试了.下面我们就来剖析一下怎么 ...

  2. jdk1.8 api 下载

    链接: https://pan.baidu.com/s/1Wmf2vzXxclVcBPUfPp_g_A 提取码: dpwu 希望那些CSDN的不要借此収积分,行行好吧你,小众程序员就是为了方便 凑字数 ...

  3. python框架之Flask基础篇(一)

    一.第一个hello world程序 # coding=utf-8 from flask import Flask app = Flask(__name__) @app.route('/') def ...

  4. 使用WindowBuilder设计Swing程序

    Swing程序表示Java的客户端窗体程序,除了通过手动编写代码的方式设计Swing程序之外,Eclipse中还提供了一种WindowBuilder工具,该工具是一种非常好用的Swing可视化开发工具 ...

  5. Jupyter(Ipython) Notebook 入门

    upyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. 一般用来编写漂亮的交互式文档. 文学编程的读者不是机器,而是人. 我们 ...

  6. JS高级——原型链

    构造函数 构造函数是特殊的函数,里面没有returen返回值 new的过程中,会自动将对象返回,不需要return new的过程中,会执行函数中的代码,会将创建的对象赋值给构造函数中的this 基本概 ...

  7. jQuery——事件操作

    事件绑定 1.简单事件绑定 $("button").click(function () {})//可重复绑定,不会被层叠 2.bind():不推荐使用 $("button ...

  8. [Windows Server 2008] 手工创建安全网站

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:手工创建安全站 ...

  9. Eclipse + Pydev开发Python时import报错解决方法

    一.  原文链接:http://blog.csdn.net/lhanchao/article/details/51306626            用eclipse +PyDev开发python时, ...

  10. python笔记之发送邮件

    发送邮件前提:开启邮箱授权码 一.开启授权码(以163邮箱为例) 1.登录163邮箱,点击设置--POP3/SMTP/IMAP,出现设置界面   2. 开启SMTP服务且可以查询SMTP的host地址 ...