maven在eclipse中的问题有哪些

60次阅读
没有评论

共计 3013 个字符,预计需要花费 8 分钟才能阅读完成。

丸趣 TV 小编给大家分享一下 maven 在 eclipse 中的问题有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

Unrecognised tag
问题
由于我使用本地代理仓库,所以 settings.xml 设置如下:

profiles 
 profile 
 id nexus /id 
 repositories 
 repository 
 id nexus /id 
 name Nexus /name 
 url http://localhost:8081/nexus/content/groups/public /url 
 releases enabled true /enabled /releases 
 snapshots enabled true /enabled /snapshots 
 /repository 
 /repositories 
 pluginRepositories 
 pluginRepository 
 id nexus /id 
 name Nexus /name  
 url http://localhost:8081/nexus/content/groups/public /url 
 releases enabled true /enabled /releases 
 snapshots enabled true /enabled /snapshots  
 /pluginRepository  
 /pluginRepositories 
 /profile  
 !-- 激活配置 -- 
 activeProfiles 
 activeProfile nexus /activeProfile 
 /activeProfiles 
 /profiles

但在 Maven 编译时报了如下异常:

[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: activeProfiles (position: START_TAG seen …\n\t… @269:18) @ C:\Documents and Settings\Administrator.ZQFGROUP.000\.m2\settings.xml, line 269, column 18
[WARNING]

解决
这是因为错把 activeProfiles 配置到了 profiles 节点里了,应该把 activeProfiles 移到 profiles 之外,更多 settings.xml 配置信息请参考这里。

No goals
问题
Eclipse 安装了 Maven 插件后,在项目的 pom.xml 上右键能看到如下:

而我自作聪明地认为:Maven build  与  mvn compile  是等价的,于是我再点击 Maven build… 之后,“Goals”是空的,如:

于是就报了这样的错误:

[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format:or:[:]:. 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-site, site, post-site, site-deploy, pre-clean, clean, post-clean. – [Help 1]

解决
解决方法至少有两种:

再点击 Maven build… 之后,输入你要执行的“Goals”,如 compile,clean,test 等等;

在 pom.xml 中配置默认的 Goal,如:

build 
 defaultGoal clean /defaultGoal 
 /build

作为 project 的子节点。

 not a JRE
问题
在使用 pom.xml 配置默认 Goal 的时,如果默认的 Goal 为 clean 就没问题,但如果是如:


就会报错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project Demo: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre7\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.

经过几番尝试,才发现并不是多个 Goal 的问题,而是 compile Goal 的问题。但使用命令的 mvn compile 又是 OK 的。
几经折腾才发现错误里说的很清楚:Please ensure you are using JDK 1.4 or above and not a JRE,它需要的是 JDK 而不是 JRE。我给的项目中使用的是公共 JRE:

解决
修改 Eclipse 的配置,使用 JDK:Eclipse- Window- Preferences- Java- Installed JREs

system propery is not set

错误:-Dmaven.multiModuleProjectDirectory system propery is not set.

新建一个环境变量 M2_HOME 指向你的 maven 安装目录
M2_HOME=D:\study\apache-maven-3.3.3
然后在 Window- Preference- Java- Installed JREs- Edit
在 Default VM arguments 中设置
-Dmaven.multiModuleProjectDirectory=$M2_HOME

5. Launching New_configuration

项目上右击 - Run/Debug Settings- 删除 new_Configuration.

以上是“maven 在 eclipse 中的问题有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-25发表,共计3013字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)