在eclipse中使用m2e构建maven项目-可能遇到的问题

在eclipse中使用m2e构建maven项目-可能遇到的问题

准备工作

首先你需要在准备本地maven仓库,如果没有请参考文章

http://blog.csdn.net/bestcxx/article/details/52126907

1、eclipse中下载m2e插件

请参考   http://blog.csdn.net/bestcxx/article/details/52126907


2、打开eclipse

file->new->other

搜索MAVEN,选择Maven Project



3、选择工作空间



4、选择archetypes

这里可能会报错,请看本文末尾可能出现的问题以及解决办法


如果正常,选择 Artifact ID 为 maven-archetype-quickstart 的,然后选择next



5、确定maven的项目名,组名,版本号,工作空间的首个package



字段含义,请参考 http://blog.csdn.net/bestcxx/article/details/52142127


6、结束,查看项目结构



7、可能遇到的问题以及解决办法

问题1:

-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn 


script match.


答案:
Window->Preference->Java->Installed JREs->Edit
在Default VM arguments中设置
-Dmaven.multiModuleProjectDirectory=$M2_HOME


问题2:

错误: 找不到或无法加载主类 D:\apache-maven-3.3.9
答案:说明没有指定编译后 .class 文件存放的路径,所以在run java application报"错误: 找不到或无法加载主类"。手动创建class文件夹,有可能默认的是build文件夹


问题3:

 Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-


prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases 


are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, 


process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, 


test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, 


post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, 


site-deploy. -> [Help 1]
答案:使用eclipse 集成环境,集成了mvn,去掉mvn前缀




问题4:

An internal error occurred during: "Retrieving archetypes:".
Java heap space
答案:
http://blog.csdn.net/yidragon88xx/article/details/42521493




问题5:

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 


将eclipse的jdk配置为jdk而不是jre,项目的也做更改


问题6:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project nexus: Failed to deploy artifacts: Could not transfer artifact stu.bestcxx.mavenssh:nexus:jar:0.0.1-20161106.102802-1 from/to snapshots (http://localhost:8081/nexus/content/repositories/snapshots/): Failed to transfer file: http://localhost:8081/nexus/content/repositories/snapshots/stu/bestcxx/mavenssh/nexus/0.0.1-SNAPSHOT/nexus-0.0.1-20161106.102802-1.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
[ERROR] 

密码不正确,看settings.xml中是否配置了servers,用户名和密码是否正确,id是否和pom.xml统一



问题7:


Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0

原因是jdk版本不对,需要看eclipse项目、eclipse工作空间已经maven运行的vm的jdk是否正确,最好刷新一下


问题8:

please make sure the -vm option in eclipse.ini is pointing to a JDK and ...


在eclipse的安装目录下找到eclipse.ini文件,增加

-vm

你的jdk的javax.exe的路径


如下

-vm
C:\Program Files (x86)\Java\jdk1.7.0_04\jre\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx1024m




评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值