在 Eclipse 中 mvn package 失败但在终端中成功后,我意识到 Eclipse 正在运行 Maven 3.3.3 而终端正在运行 3.3.9。我尝试通过转到 Eclipse -> Preferences -> Maven -> Installations
并指向我的 3.3.9 文件夹来重新配置 Eclipse,并且显然成功了。我重新启动 Eclipse 并再次尝试但没有可用。此外,尝试构建时不会确认对 pom.xml
文件的更改。我插入了不合适的斜杠和其他字符,并且只能生成此错误:
组装 WAR 时出错:需要 web.xml 属性(如果在更新模式下执行,则需要预先存在的 WEB-INF/web.xml)
我根据 this 修改了我的 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>
最佳答案
尝试设置一个运行时配置,或者看看您是否已经在使用一个。
在eclipse中,右击project->run as->run configurations。在左侧查找 m2 Maven Build
部分。如果您的项目名称下有一个,则编辑它,否则创建一个。在对话框的底部有一个下拉菜单,允许您选择要运行的 Maven 配置:
这给了我以下输出:
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"
关于java - 无法在 Eclipse IDE 中更改 Maven 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35531031/