首页 技术 正文
技术 2022年11月8日
0 收藏 658 点赞 1,411 浏览 2751 个字

在使用Maven以及Eclipse的Maven插件时,我和同事遇到了一下几个问题,本着知其然知其所以然的学习精神,总结如下:

  1. 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配置信息请参考这里

  2. No goals
    问题
    Eclipse安装了Maven插件后,在项目的pom.xml上右键能看到如下:
    Maven与Eclipse使用中遇到的问题解决之道
    而我自作聪明地认为:Maven buildmvn compile 是等价的,于是我再点击”Maven build…”之后,“Goals”是空的,如:
    Maven与Eclipse使用中遇到的问题解决之道
    于是就报了这样的错误:

    [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的子节点。

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

    <build>
    <defaultGoal>clean compile</defaultGoal>
    </build>

    就会报错误:

    [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:
    Maven与Eclipse使用中遇到的问题解决之道
    解决
    修改Eclipse的配置,使用JDK:Eclipse->Window->Preferences->Java->Installed JREs
    Maven与Eclipse使用中遇到的问题解决之道
    Finish后,项目如:
    Maven与Eclipse使用中遇到的问题解决之道

OK,知之为知之,不知创造条件必须知Maven与Eclipse使用中遇到的问题解决之道!!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918