Maven3.0.3


------------------------------------M2E安装--------------------------------------------------

1.subvision    http://subclipse.tigris.org/update_1.4.x

2.gef http://download.eclipse.org/tools/gef/updates/interim

3.m2e http://m2eclipse.sonatype.org/sites/m2e

4.m2e-extra              http://m2eclipse.sonatype.org/sites/m2e-extras

5.修改eclipse.ini文件          在-vmargs前面加上

-vm

F:\java\jdk1.6.0_24\bin\javaw.exe

 

-------------------------------------Maven中央仓库-------------------------------------

http://repo1.maven.org/maven2/

-------------------------------------Maven是什么------------------------------------------

一个更正式的 Apache Maven1 的定义: Maven是一个项目管理工具,它包含了一个项目对象模型 (Project Object Model),一组标准集合,一个项目生命周期(Project Lifecycle),一个依赖管理系统(Dependency Management System),和用来运行定义在生命周期阶段(phase)中插件(plugin)目标(goal)的逻辑。

-------------------------------------Maven目录结构------------------------------------------

标准目录结构:
src
  -main
      –bin 脚本库
      –java java源代码文件
      –resources 资源库,会自动复制到classes目录里
      –filters 资源过滤文件
      –assembly 组件的描述配置(如何打包)
      –config 配置文件
      –webapp web应用的目录。WEB-INF、css、js等
  -test
      –java 单元测试java源代码文件
      –resources 测试需要用的资源库
      –filters 测试资源过滤库
  -site Site(一些文档)
target
LICENSE.txt Project’s license
README.txt Project’s readme

 

-------------------------------------Maven命令------------------------------------------

1   mvn clean compile                      主代码编译

2 mvn clean test    测试

3 mvn clean package   打包

4 mvn clean install 打包后安装到本地仓库

5      mvn archetype:generate         生成项目骨架(maven3)

        mvn groupId:artifactId:version:generate        生成项目骨架(maven2)

6  mvn dependency:list 查看当前项目的已解析依赖

    mvn dependency:resolve

    mvn dependency:tree         查看整个项目的依赖树

    mvn dependency:analyze 帮助分析当前项目的依赖

 

----------------------------------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">
	
	<build>
		<plugins>
			<!-- 插件配置 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>1.2.1</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
								<mainClass>com.wgk.mvntest.helloworld.HelloWorld</mainClass>
							</transformer>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	
	
	<!-- groupId,artifactId和version这三个元素定义了一个项目基本的坐标 -->
	<!-- Maven项目隶属的实际项目,一般以包结构的形式表示 -->
	<groupId>com.wgk.mvntest</groupId>
	<!-- Maven项目中唯一标识   -->
	<artifactId>hello-world</artifactId>
	<!-- SNAPSHOT译为快照,表示该版本正处于开发中 -->
	<version>1.0-SNAPSHOT</version>
	<name>Maven Hello World Project</name>
	<!-- 依赖 -->
	<dependencies>
		<dependency>
			<!-- 它会自动访问中央仓库,下载对应的版本junit -->
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.7</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	
</project>

 

----------------------------依赖范围------------------------------------------------

名称                       备注                       编译                      测试                   运行

compile            编译依赖范围。               √                           √                      √

test                  测试依赖范围。               ×                            √                      ×

provided          已提供依赖范围。            √                             √                      ×

runtime            运行时依赖范围。            ×                             √                      √

system             系统依赖范围。               √                             √                      ×

import              导入依赖范围。

 

传递性依赖(最左边第一传递依赖,最上方第二传递依赖)

 

compiletestprovidedruntime
compilecompile   --runtime
testtest--test
providedprovided-providedprovided
runtimeruntime--runtime

 

-----------------------------------settings.xml-------------------------------------

localRepository:        表示本地库的保存位置,也就是maven主要的jar保存位置,默认在                                                                          ${user.dir}/.m2/repository,如果需要另外设置,就换成其他的路径。

interactiveMode:       如果Maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认

                                     为true。

 offline:                      如果不想每次编译,都去查找远程中心库,那就设置为true。当然前提是你已经                                                         下载了必须的依赖包。

usePluginRegistry:     如果需要让Maven使用文件plugin-registry.xml来管理插件版本,则设为true。                                                       默认为false。

proxies:                        多个proxy profile配置。当你在其它平台工作时,能方面切换。

servers:                         一些需要验证的服务器配置,每个服务器都可以有不同配置。

mirros:                          仓库的下载镜像。

profiles:                         项目构建的配置信息,这里会有单独说明。

activeProfiles:             激活的profile列表,按顺序生效。

pluginGroups:                如果插件groupId未指明,按该列表下的id去查找。

---------------------------------------------生命周期-------------------------------------

生命周期 目标绑定

process-resources -------- resources:resources

compile  -------- compiler:compile

process-classes

process-test-resources  -------- resources:testResources

test-compile  -------- compiler:testCompile

test    -------- surefire:test

prepare-package

package  -------- jar:jar

-----------------------------------help插件四个目标-------------------------------------

help:active-profiles

列出当前构建中活动的Profile(项目的,用户的,全局的)。

help:effective-pom

显示当前构建的实际POM,包含活动的Profile。

help:effective-settings

打印出项目的实际settings, 包括从全局的settings和用户级别settings继承的配置。

help:describe

描述插件的属性。它不需要在项目目录下运行。但是你必须提供你想要描述插件的 groupId 和 artifactId。

 

 

下面的命令列出了Compiler 插件的 compile 目标的所有信息

 

$ mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull                                                                     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值