1. 一个简单的项目 (1) 创建一个项目 mvn archetype:create -DgroupId=com.like.maven -DartifactId=example -DpackageName=com.like.maven (2) 安装这个项目(创建,编译,测试,打包,安装) mvn install 2. 简单的项目对象模型 (1) 这是刚创建项目的pom.xml文件 <modelVersion>4.0.0</modelVersion> <groupId>com.like.maven.study</groupId> <artifactId>Simple</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Simple</name> <url>http://maven.</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> (2) groupId, artifactId, packaging, version是Maven的坐标,它们唯一标示了这个项目 groupId d 团体,公司,小组,组织,项目,或者其它团体。团体标识的约定是,它以创
建这个项目的组织名称的逆向域名(reverse domain name)开头。来自Sonatype
的项目有一个以com.sonatype开头的groupId,而Apache Software的项目有以
org.apache开头的groupId。 artifactId 在groupId下的表示一个单独项目的唯一标识符。 version 一个项目的特定版本。发布的项目有一个固定的版本标识来指向该项目的某一个
特定的版本。而正在开发中的项目可以用一个特殊的标识,这种标识给版本加上
一个“SNAPSHOT”的标记。 packaging 项目的类型,默认是jar,描述了项目打包后的输出。类型为jar的项目产生一个
JAR文件,类型为war的项目产生一个web应用。 3. 依赖范围 (1) test 当一个依赖的范围是test的
时候,说明它在Compiler插件运行compile目标的时候是不可用的。它只有在运
行compiler:testCompile和surefire:test目标的时候才会被加入到classpath中。 (2) provided provided范
围告诉Maven一个依赖在编译的时候需要,但是它不应该被捆绑在构建的输出中。 (3) compile |
|