Maven学习笔记(一) 安装和构建简单应用

一、安装

http://maven.apache.org/上下载最新版本(现在为3.0.4),解压,配置环境变量

M2_HOME=D:\apache-maven-3.0.4
M2=%M2_HOME%\bin
Path=%M2%

命令行输入mvn -v 测试成功

二、构建简单应用

 mvn archetype:generate -DgroupId=org.sonatype.mavenbook.ch04 -DartifactId=simple-weather  -DpackageName=org.sonatype.mavenbook -Dversion=1.0

三、添加eclipse IDE支持

(1)在eclipse安装m2eclipse(m2e)插件

(2)导入项目到eclipse中

Import->Maven->Existing Maven Projects->Next->Finish.

四、添加pom添加依赖

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.wang.mvtest</groupId>
	<artifactId>simple-weather</artifactId>
	<version>1.0</version>
	<packaging>jar</packaging>

	<name>simple-weather</name>
	<url>http://maven.apache.org</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>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.16</version>
		</dependency>
		<dependency>
			<groupId>dom4j</groupId>
			<artifactId>dom4j</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>jaxen</groupId>
			<artifactId>jaxen</artifactId>
			<version>1.1.3</version>
			<exclusions>
				<exclusion>
					<groupId>maven-plugins</groupId>
					<artifactId>maven-cobertura-plugin</artifactId>
				</exclusion>
				<exclusion>
					<groupId>maven-plugins</groupId>
					<artifactId>maven-findbugs-plugin</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>velocity</groupId>
			<artifactId>velocity</artifactId>
			<version>1.5</version>
		</dependency>
		<dependency>
			<groupId>avalon-logkit</groupId>
			<artifactId>avalon-logkit</artifactId>
			<version>2.1</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
					<archive>
						<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
					</archive>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

修改src/main/resources/META-INF/MANIFEST.MF并添加项目源码

五、构建项目
mvn package assembly:assembly

六、附录:

mvn package

mvn install

mvn test

mvn exec:java -Dexec.mainClass=myclassname

其他mvn命令参考官方帮助文档

若在eclipse中,需将src/main/java,src/test/java,sec/main/resource均加入classpath,否则可能找不到文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值