A JBoss Project
Red Hat

Posts tagged with 'm2e'

I previously decribed how to use a combination of maven-war-plugin webresources and Maven profiles, in order to deploy minified resources. In this article, we’ll expand on these concepts a bit, to demonstrate how to deploy test resources, in a somewhat elegant and portable way.

User story

In some cases, you want your web application to deploy test resources, whether it’s logging or database configuration files, or even some test mocks during development.

When you’re using Eclipse Java EE, m2e-wtp explicitely prevents test resources from being deployed (in order to limit behavior discrepancies between Maven CLI and Eclipse), and if you try to mess with Eclipse’s Deployment Assembly page, its settings will be reset next time you perform a Maven > Update projet configuration.

So you need a solution that works for both Eclipse, command line and even other IDEs as well. Let’s see how you can achieve that…​

Pre-requisites

You only need :

  1. a Java EE based Eclipse distribution for the following to work: stock Eclipse, JBoss Developer Studio or SpringSource Tools Suite for instance, as long as m2e-wtp is installed with it.

  2. a Maven project with packaging war

Configure a new dev profile

In order to deploy test resources with WTP, we need to add a new Maven dev profile to the <profiles> section of your pom.xml. This can easily be done with Ctrl+space assist. Selecting the m2e profile template and changing the id to dev will get you started.

The profile is automatically enabled when running in m2e, via the m2e.version property.

Then, you need to add a maven-war-plugin configuration to the <build><plugins> section of the new profile, and configure <webResources> so that test resources from the test output directory are copied to WEB-INF/classes, using a regexp to only include specific files.

Eventually, this is how your dev profile should look :

<profile>
  <id>dev</id>
  <activation>
    <property> <!-- this will automatically be enabled when using m2e -->
    <name>m2e.version</name>
    </property>
  </activation>
  <build>
    <plugins>
    ...
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <!-- this will inherit existing maven-war-plugin configuration-->
        <configuration>
          <webResources>
            <resource>
              <directory>${project.build.testOutputDirectory}</directory>
              <includes>
                <include>**/some/test/resources/**</include>
              </includes>
              <targetPath>WEB-INF/classes/</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>

In Eclipse, the matching test resources are not served directly but are actually copied/processed to target/m2e-wtp/web-resources/WEB-INF/classes and deployed from there.

If the original configuration already defines <webResources>, use <webResources combine.children="append"> in the dev profile, so all resources get deployed. You can learn more about merging plugin configuration on the Sonatype blog.

If you decide to declare this profile in a parent pom, don’t forget to put the <plugins> node under the <pluginManagement> section, or else, these configurations will not be inherited by your war projects.

This extra configuration will be merged to your existing maven-war-plugin configuration (check the maven-war-plugin configuration in the Effective POM tab of the pom.xml editor).

Now, using m2e-wtp, every time a test resource is modified, it will automatically be deployed to your server, on-the-fly. This is borderline magic, I know.

Conclusion

Hopefully, this article gave you a glimpse of the powerful Maven capabilities m2e-wtp brings to Eclipse, showing how you can easily deploy your test resources in your development environment in a portable way.

Take it easy!

The Maven Integration for Eclipse plugin, a.k.a. m2e, released version 1.5.0 a few weeks ago, as part of the annual Eclipse release train, this year known as Luna. 77 Bugs were fixed as part of that release, compatible with both Eclipse Kepler and Luna. I believe it’s a pretty solid one, with numerous interesting fixes and usability improvements that deserve a blog post. So here goes, in no particular order:

Improved project import workflow

Selecting Maven projects to import used to take an inordinate amount of time, due to a suboptimal - I love that word :-) - Maven Lifecycle Mapping Analysis (LMA). LMA is used to determine whether the projects would require further configuration to operate properly in Eclipse. That LMA is now only run after projects are imported, making selection of projects to import much, much faster (< couple seconds vs 1-2 min for the wildfly 8.0 codebase and its 130 projects, for instance)

After import, lifecycle mapping error markers are collected on imported projects and the discovery service is invoked to find proposals to fix those errors.

Another improvement to this workflow is the ability to easily import multi-module projects to an Eclipse Working Set. The default name is inferred from the root project but can be overridden manually:

m2e workingset import

More performance improvements during import itself are to be expected to be included in m2e 1.6.0.

See bugs 409732, 408042 and 417466.

Improved memory consumption

Maven project instance caching strategy has been revisited to reduce memory consumption. For a workspace with 300+ projects for instance, heap memory used went from 2.5GB down to well under 1GB without any noticeable side effects.

Nexus index download disabled by default

Before m2e 1.5, by default, Nexus indexes were downloaded on new workspace startup, then subsequently once a week. Depending on your internet connection, that whole process could take 15 minutes or more, heavily pegging the CPU. Once the indexes were updated, the size of the workspace would increase by approximately 500 MB. Even though space is relatively cheap these days, those with many workspaces (eg., for testing) or large workspaces, this extra disk usage can add up quickly.

m2e 1.5.0 now has this feature disabled by default. You can still enable it in Preferences  Maven  Download repository index updates on startup. One major downside of having this feature disabled by default though, is Archetype and Artifact/Plugin searches are now much less efficient, as they rely on this indexed content.

See bug 404417

New Maven Profile management UI

The JBoss Tools team contributed its Maven Profile management interface to m2e 1.5.0. This new interface eases switching between profiles.

Rather than right-clicking on a project, going to the Properties  Maven page, then manually (mis)typing a list of active or disabled profiles, you can now just use Ctrl+Alt+P to open the new Maven Profile selection interface.

m2e profile selection

The new interface is also accessible from the Maven context menu: Right-click project Maven  Select Maven Profiles…​

The list of available profiles is inferred from profiles defined in:

  • the project pom.xml

  • the project’s parent hierarchy

  • user and global maven settings.xml

When several projects are selected, only the common available profiles are displayed for selection. Common profiles are profiles defined in settings.xml or profiles having the same id in different pom.xml.

You can learn more about that feature from the original JBoss Tools blog

See bug 428094

Easily update outdated projects

The Update Maven Project dialog (launched via Right-click project Maven  Update Project…​ or via Alt-F5), now shows a dirty overlay on projects which need updating.

Additionally, an "Add out-of-date" button adds all out-of-date (OOD) projects to the current selection. If an OOD project has not been selected, a warning is shown underneath the selection table with a link equivalent to "Add out-of-date". Warning text and "Add out-of-date" button tooltip show a count of unselected OOD projects.

m2e select ood projects

See bug 422667

No more Unsupported IClasspathEntry kind=4

There’s a very popular question on StackOverflow about an m2e bug that plagued many users of the maven-eclipse-plugin: m2e would throw Unsupported IClasspathEntry kind=4 exceptions on classpath entries generated by the maven-eclipse-plugin (one of the reasons why you should never mix maven-eclipse-plugin and m2e).

m2e 1.5.0 no longer complains about these unsupported classpath entries, but unexpected classpath issues may still arise, should you mix duplicate jars from m2e and those added by the maven-dependency-plugin.

New checksum settings

Ever connected to a network with limited Internet access or simply stayed at a hotel where you needed to get past a for-pay-firewall, resulting in HTML pages being downloaded instead of jars? There’s nothing better to pollute your local Maven repository. Maven CLI builds can use these flags:

  • -C - fail build if checksums do not match

  • -c - warn if checksums do not match

m2e now has a global Checksum Policy available in Preferences  Maven, that will help you keep your sanity, and yor local repository clean:

m2e checksum policy flag

While m2e actually won’t create any Warning markers on projects when "Warn" is selected, it will override existing checksum policies set on repositories.

Improved settings for Errors/Warnings preferences

m2e has been known for generating specific errors that have puzzled more than one user in the past:

  • Project Configuration is not up-to-date - a change in pom.xml might require a full project configuration update.

  • Plugin execution not covered by lifecycle - m2e doe not know if it is safe to execute a maven plugin as part of the Eclipse build

With the new Preferences  Errors/Warnings page, users can now decide according to their own needs whether these errors should be downgraded to Warning, or even be ignored entirely.

m2e warnerrors prefs

See bugs 433776, 434053

Maven runtime changes

A few changes have been made with regards to the Maven runtime(s):

  • The embedded Maven runtime has been updated to maven 3.2.1.

  • The Netty/AsynHttpClient transport layer as been replaced with OkHttp 1.5.4. OkHttp is now the default HTTP client on the Android platform. It brings HTTP 2.0 and SPDY support to artifact downloads. Please note though, NTLM authentication is not supported.

  • Maven runtime installations can now be customized with a name, and additional libraries can be added. Maven Launch configurations now reference the Maven runtime by name, instead of using a hard-coded location so the configuration is more portable.

See bugs 427932, 418263, 432436

Accept contributions from Gerrit

In order to lower the contribution barrier and increase contributor diversity, the m2e project now accepts changes contributed via the Gerrit review system. Head over the wiki that explains how to use it. Does it work? Hell yeah! After several significant contributions, Anton Tanasenko has joined the m2e team as commiter!

Welcome Anton!

See bug 374665

Conclusion

With new blood on the m2e team, numerous fixed bugs and some big new features & improvements, m2e 1.5.0 is a pretty exciting release. Hope you guys appreciate this year’s release, before an even better version next time.

So if you haven’t installed m2e 1.5.0 yet, head over to https://www.eclipse.org/m2e/download/ and have at it.

We’d love to hear your feedback on the mailing list, or whether you report bugs or enhancement requests.

Fred Bricon
@fbricon

JBoss Tools 4.29.0.Final for Eclipse 2023-09

by Stéphane Bouchet on Nov 02, 2023.

JBoss Tools 4.28.0.Final for Eclipse 2023-06

by Stéphane Bouchet on Jul 03, 2023.

JBoss Tools for Eclipse 2023-06M2

by Stéphane Bouchet on Jun 05, 2023.

JBoss Tools 4.27.0.Final for Eclipse 2023-03

by Stéphane Bouchet on Apr 07, 2023.

JBoss Tools for Eclipse 2023-03M3

by Stéphane Bouchet on Mar 10, 2023.

Looking for older posts ? See the Archived entries.
back to top