Maven入门踩坑

刚刚入门Maven,记录一下踩过的坑。希望对大家有帮助。

(1)下载依赖jar时,默认仓库太慢了
可以换源,这里以阿里的源为例。修改配置文件\apache maven\conf\settings.xml,在mirrors中添加下述信息:

<mirrors>
	<mirror>
		<id>alimaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</mirrorOf>
	</mirror>
</mirrors>

另外在项目pom.xml中添加下述定义远程库为阿里库:

<repositories>  
	<repository>  
		<id>alimaven</id>  
		<name>aliyun maven</name>  
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
		<releases>  
			<enabled>true</enabled>  
		</releases>  
		<snapshots>  
			<enabled>false</enabled>  
		</snapshots>  
	</repository>  
</repositories>

(2)“[ERROR] 不再支持源选项 1.5。”
在项目的pom.xml中添加下述属性指定编译版本,顺便指定UTF编码:

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<maven.compiler.source>1.8</maven.compiler.source>
	<maven.compiler.target>1.8</maven.compiler.target>
</properties>

(3)利用junit进行单元测试无法找到jar / @Test注解报错
junit的3.x版本为编程方式,而4.x是注解方式,因此需要使用高版本替换默认低版本。在pom.xml中添加下述依赖说明:

<repositories> 
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.12</version>
		<scope>test</scope>
	</dependency>
</repositories> 

(4)mvn test没有测试输出,或者缺失测试统计信息
这个不清楚是不是版本问题,需要在项目pom.xml内为maven-surefire-plugin指定测试的.java路径,即在文件中添加如下信息:

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.10</version>
			<configuration>
				<includes>
					<include>**/hellotest.java</include>
				</includes>
			</configuration>
		</plugin>
	</plugins>
</build>

(5)利用maven直接执行项目类的main函数
将自动加载exec-maven-plugin插件:

mvn exec:java -Dexec.mainClass="xxx.xxx.xxx" [-Dexec.args="arg1 arg2 arg3"]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值