Over a million developers have joined DZone.

Webapps with Eclipse and Maven (maven-war-plugin)

DZone's Guide to

Webapps with Eclipse and Maven (maven-war-plugin)

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

Web applications created by the Eclipse IDE contains an annoying folder WebContent to host the web resources and deployment descriptors. While natural for Eclipse users, this feature ignores the Maven convention and force the developers to hack the pom files in order to get the project up and running in Eclipse. Eclipse if far behind the other IDEs regarding Maven support, even if you consider the very good M2Eclipse plugin. So, for you lazy Christmas hackers, here it is a solution for the Maven integration problems in Eclipse based on the maven-war-plugin.

ERRATA I: John J. Franey proved the usability of the Sonatype plugin to get better results than the instructions in my blog. Please check this screencast and the comments at the end of this page.


ERRATA II: please use the WTP plugin instead of changing the project structure.  I figured out the wtp plugin after writting this blog, so I suggest you to check just the 1st and the 3th steps of the below instructions. I kept the original blog information in case you really need or want to change the project structure.

  1. Create a Web Project in Eclipse: right-click on the Project Explorer > New > Project > Web \ Dynamic Web Project

  2. Create a pom.xml file in the project root folder, with the following content:

    <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 <a target="_blank" href="http://maven.apache.org/maven-v4_0_0.xsd%22%3E" title="http://maven.apache.org/maven-v4_0_0.xsd">">http://maven.apache.org/maven-v4_0_0.xsd"></a>
    <name>webapp-test Maven Webapp</name>
    <name>Java.net Repository for Maven</name>

    <classpathPrefix />
  3. Compile and prepare the project for eclipse:

    mvn -Dwtpversion=2.0 compile eclipse:eclipse

Notice the usage of the plugin -Dwtpversion to enable Maven to add Eclipse WTP Support to the project. That simple flag do the trick :). Actually just using that flag will work, but not all plugins of Eclipse will work out of the box without the WebContent folder - it is up to you to decide if it is worthy to modify your project structure or just go straight ahead with the plain Maven folder.

Done, now you can refresh the project in Eclipse and continue to work. Remember that jjust the resources folder is hard coded in Eclipse, the src/main/java continues as Maven expects. Perhaps some day we can have the confluence between the conventions of Maven and Eclipse and then we will finally becomes free of this daily basis hacks

From http://weblogs.java.net/blog/felipegaucho

Merry Christmas and Happy New Year!

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}