DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Part 3 of My OCP Journey: Practical Tips and Examples
  • How To Use an Automatic Sequence Diagram Generator
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Performance Comparison — Thread Pool vs. Virtual Threads (Project Loom) In Spring Boot Applications

Trending

  • Part 3 of My OCP Journey: Practical Tips and Examples
  • How To Use an Automatic Sequence Diagram Generator
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Performance Comparison — Thread Pool vs. Virtual Threads (Project Loom) In Spring Boot Applications
  1. DZone
  2. Coding
  3. Frameworks
  4. Webapps with Eclipse and Maven (maven-war-plugin)

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

Felipe Gaúcho user avatar by
Felipe Gaúcho
·
Dec. 28, 09 · Interview
Like (0)
Save
Tweet
Share
41.74K Views

Join the DZone community and get the full member experience.

Join For Free

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>
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.cejug</groupId>
    <artifactId>webapp-test</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>webapp-test Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <repositories>
    <repository>
    <id>maven2-repository.dev.java.net</id>
    <name>Java.net Repository for Maven</name>
    <url>http://download.java.net/maven/2</url>
    </repository>
    </repositories>

    <build>
    <finalName>${project.name}</finalName>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
    <webResources>
    <resource>
    <directory>${basedir}/WebContent</directory>
    </resource>
    </webResources>
    <warSourceDirectory>WebContent</warSourceDirectory>
    <warSourceExcludes>WebContent/WEB-INF/lib/*.jar</warSourceExcludes>
    <archiveClasses>false</archiveClasses>
    <archive>
    <manifest>
    <addClasspath>true</addClasspath>
    <classpathPrefix />
    </manifest>
    <manifestEntries>
    <url>${pom.url}</url>
    <Implementation-Build>${buildNumber}</Implementation-Build>
    <Implementation-Title>${project.name}</Implementation-Title>
    <Implementation-Vendor>CEJUG</Implementation-Vendor>
    <Implementation-Version>${project.version}</Implementation-Version>
    <Built-By>${user.name}</Built-By>
    <Built-OS>${os.name}</Built-OS>
    <Build-Date>${timestamp}</Build-Date>
    <SCM>${buildNumber}</SCM>
    </manifestEntries>
    </archive>
    </configuration>
    </plugin>
    </plugins>
    </build>
    </project>
  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!

Eclipse Apache Maven

Opinions expressed by DZone contributors are their own.

Trending

  • Part 3 of My OCP Journey: Practical Tips and Examples
  • How To Use an Automatic Sequence Diagram Generator
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Performance Comparison — Thread Pool vs. Virtual Threads (Project Loom) In Spring Boot Applications

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: