11

After failing to mvn package inside of Eclipse but succeeding in the terminal, I realized that Eclipse was running Maven 3.3.3 while 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.9 folder. 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:

Error assembling WAR: web.xml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

I modified my pom file as per this recommendation but as I said, maven is not recognizing changes to the pom and I cannot get running mvn --version to produce 3.3.9 as it should. I've attached my pom.xml below

<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>

Community
  • 1
  • 1
Austin Wehn
  • 113
  • 1
  • 1
  • 4
  • First don't use back slashes in a pom file, cause you can use slashes instead which is platform independent. Furthermore you don't need to set the path to `web.xml` cause the default is having it in `src/main/webapp/WEB-INF/web.xml`....Apart from that if you get the message `WAR: web.xml attribute is required`you should put one into the appropriate location. If you are sure you don't need it this can be achieved by using `false`...and very important. Define the versions of the plugins you are using....BTW.: I would never package inside of Eclipse.. – khmarbaise Feb 21 '16 at 12:37

3 Answers3

18

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:

enter image description here

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"
K.Nicholas
  • 10,956
  • 4
  • 46
  • 66
9
  • Call cmd, type systempropertiesadvanced Check environment variables: %MAVEN_HOME%, %PATH%.
  • Check these steps: enter image description here



Look at the below screenshot (this is relate to your problem):

EMBEDDED: 3.3.3
outsite Eclipse: 3.3.9

enter image description here

enter image description here

enter image description here

enter image description here

(source: http://codingvn.com/2016/02/08/cau-hinh-de-eclipse-su-dung-ban-cai-dat-maven-ben-ngoai-ide/ this is my website)

Community
  • 1
  • 1
Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • 3
    You can still get dependency errors that are version specific using this. See the note at the bottom of the installation screen: "Note: Embedded runtime is always used for dependency resolution". – John Dec 16 '18 at 17:26
  • Works for me in Mac as well – Yao Li Jan 30 '20 at 18:01
  • does not work, eclipse for me is still using the embedded maven version – mounaim Apr 03 '20 at 13:37
0

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.

randombee
  • 699
  • 1
  • 5
  • 26