Search code examples
eclipsem2eclipsem2e

eclipse m2e default plugins settings


Env:

Eclipse (mars)
JDK 8 
Wildfly 8.2.0 Final

Issue: Everytime i create a maven project

  • it uses JDK 5 (war and jar)
  • complains that web.xml is missing (in case of war).

So, everytime i have to

  1. Open the pom.xml and include the plugin configuration in pom.xml

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.6</version>
          <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.3</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  1. Change eclipse project compiler settings to use 1.8
  2. Change JRE to use 1.8
  3. Manually update maven project settings

This is a real frustrating thing to do. Tried to

  • find a solution in stackoverflow and google. Somewhat closer solution is here. It works but is not enough for me.
  • find any settings in eclipse but to no avail
  • find any xml file settings in eclipse m2e plugins but got nowhere

Would be very greatful if someone

  • point me if i am missing some settings
  • can offer any solution to this pestering issue.

Please note that i am able to resolve the issues (eclipse errors and m2e errors) but looking for a smarter solution to avoid menial work every time!

Thanks in advance, Rakesh


Solution

  • The default settings you see come from default maven plugin settings.

    • The maven-compiler-plugin targets java 1.5
    • the maven-war-plugin has failOnMissingWarXml=true by default

    The goal for m2e is to stay as close as what an actual Maven CLI build would produce. So if you want your project to build in command line or a CI server, you need to have these maven plugin settings.

    In your workflow, you actually don't need to do steps #2 and #3. Executing Maven > Update project configuration (or Ctr+Alt+F5), will take care of that. You can also enable Automatic Project configuration update in Preferences > Maven (since m2e 1.6), so all you have to do is do your pom changes and save the file.

    If you want to have more control on these maven settings during project creation however, you have 2 options:

    • Make your new Maven project inherit a parent pom, which has the maven-compiler-plugin and maven-war-plugin settings you want
    • Instead of creating a new Maven project, create a new Dynamic Web Project first. You can change the default Java and Web Facets in that Eclipse wizard Then change the default src folder to src/main/java, and change the default WebContent folder to src/main/webapp. Once the project is created, you can convert it to a Maven project (Right-click on project, Configure > Convert to Maven...). Give it the appropriate project coordinate, and when you hit finish, the generated Maven pom.xml will get maven plugin settings mapped to the original Eclipse settings.

    A third solution would be to create a project from an existing Maven archetype. You can try wildfly-javaee7-webapp-blank-archetype, from the Maven Central catalog, to create a JavaEE 7 web project for instance ( (http://search.maven.org/#artifactdetails%7Corg.wildfly.archetype%7Cwildfly-javaee7-webapp-blank-archetype%7C8.2.0.Final%7Cmaven-archetype). Using JBDS or JBoss Tools Maven integration (http://tools.jboss.org) you'll have access to the Maven Central Archetype catalog by default. Else, you can add it yourself in Preferences > Maven > Archetypes > Add Remote Catalog... Use http://repo1.maven.org/maven2/ for the catalog file, and whatever description you like.