Java 无法在 Eclipse IDE 中更改 Maven 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35531031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot change Maven version in Eclipse IDE
提问by Austin Wehn
After failing to mvn package inside of Eclipse but succeeding in the terminal, I realized that Eclipse was running Maven 3.3.3while terminal was running 3.3.9. I attempted, and by all apparent accounts succeeded, to reconfigure eclipse by going to Eclipse -> Preferences -> Maven -> Installations
and pointing to my 3.3.9folder. I restarted Eclipse and tried again but to no available. Also, changes to the pom.xml
file are not acknowledged when attempting to build. I've inserted inappropriate slashes and other characters and am only able to generate this error:
在 Eclipse 中 mvn package 失败但在终端中成功后,我意识到 Eclipse 正在运行Maven 3.3.3而终端正在运行3.3.9。我试图通过转到Eclipse -> Preferences -> Maven -> Installations
并指向我的3.3.9文件夹来重新配置 eclipse,并且所有明显的帐户都成功了。我重新启动 Eclipse 并再次尝试,但没有可用。此外,pom.xml
尝试构建时不会确认对文件的更改。我插入了不适当的斜杠和其他字符,并且只能生成此错误:
Error assembling WAR: web.xml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
组装 WAR 时出错:需要 web.xml 属性(如果在更新模式下执行,则需要预先存在的 WEB-INF/web.xml)
I modified my pom file as per thisrecommendation but as I said, maven is not recognizing changes to the pom and I cannot get running mvn --version
to produce 3.3.9as it should. I've attached my pom.xml
below
我按照此建议修改了我的 pom 文件,但正如我所说,maven 无法识别对 pom 的更改,我无法按预期运行mvn --version
生成3.3.9。我附上了我的pom.xml
下面
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javawebtutor</groupId>
<artifactId>LoginWebApp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>LoginWebApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
<build>
<finalName>LoginWebApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
回答by randombee
Normally you have to reinstall the m2eclipse plugin to run with the correct version. If it was updated, it won't work with the previous one, as it will take the "old" maven version.
通常,您必须重新安装 m2eclipse 插件才能以正确的版本运行。如果它被更新,它将无法与前一个一起使用,因为它将采用“旧”的 maven 版本。
回答by K.Nicholas
Try setting up a runtime configuration, or see if you're using one already.
尝试设置运行时配置,或者看看您是否已经在使用。
In eclipse, right click on the project->run as->run configurations. Look for the m2 Maven Build
section on the left. If there is one under your project's name, then edit it, otherwise, create one. On the bottom of the dialog there is a drop down that allows you to select which maven configuration you want to run:
在eclipse中,右键单击项目->运行方式->运行配置。寻找m2 Maven Build
左侧的部分。如果您的项目名称下有一个,则对其进行编辑,否则,创建一个。在对话框底部有一个下拉菜单,允许您选择要运行的 maven 配置:
This gives me the following output:
这给了我以下输出:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11 10T11:41:47-05:00)
Maven home: C:\Program Files\Java\apache-maven-3.3.9
Java version: 1.7.0_80, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_80\jre
Default locale: en_US, platform encoding: UTF-8
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"
回答by Do Nhu Vy
- Call
cmd
, typesystempropertiesadvanced
Check environment variables:%MAVEN_HOME%
,%PATH%
. - Check these steps:
Look at the below screenshot (this is relate to your problem):
看下面的截图(这与你的问题有关):
EMBEDDED: 3.3.3
outsite Eclipse: 3.3.9
嵌入式:3.3.3
外部 Eclipse:3.3.9
(source: http://codingvn.com/2016/02/08/cau-hinh-de-eclipse-su-dung-ban-cai-dat-maven-ben-ngoai-ide/this is my website)
(来源:http: //codingvn.com/2016/02/08/cau-hinh-de-eclipse-su-dung-ban-cai-dat-maven-ben-ngoai-ide/这是我的网站)