How to convert Maven based web application to support Eclipse IDE
In last tutorial, you created a web application with Maven. Here’s a guide to show you how to convert that web application to support Eclipse IDE.
Eclipse IDE support web application via WTP tool, so you need to make your Maven based project support it as well.
1. mvn eclipse:eclipse -Dwtpversion=2.0
To convert a Maven based Java project to support IDE, you use this command :
mvn eclipse:eclipse
For web application, you need extra parameter to make it support Eclipse’s wtp, instead, you should use this command :
mvn eclipse:eclipse -Dwtpversion=2.0
See output …
D:\workspace-new\mkyongweb-core>mvn eclipse:eclipse -Dwtpversion=2.0 [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] ------------------------------------------------------------------------ [INFO] Building mkyongweb-core Maven Webapp [INFO] task-segment: [eclipse:eclipse] [INFO] ------------------------------------------------------------------------ [INFO] Preparing eclipse:eclipse [INFO] No goals needed for project - skipping [INFO] [eclipse:eclipse {execution: default-cli}] [INFO] Adding support for WTP version 2.0. [INFO] Using Eclipse Workspace: D:\workspace-new [INFO] no substring wtp server match. [INFO] Using as WTP server : Apache Tomcat v6.0 [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaults suffice [INFO] Wrote Eclipse project for "mkyongweb-core" to D:\workspace-new\mkyongweb-core. [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Fri Apr 15 11:51:53 SGT 2011 [INFO] Final Memory: 7M/14M [INFO] ------------------------------------------------------------------------
2. Eclipse WTP
Standard Eclipse’s “.classpath” and “.project” files are created. And you will noticed a new “.setting” folder is created and inside contains “org.eclipse.wst.common.component” and “org.eclipse.wst.common.project.facet.core.xml“, both files for WTP or Faces support in Eclipse.
File : org.eclipse.wst.common.project.facet.core.xml
<faceted-project> <fixed facet="jst.java"/> <fixed facet="jst.web"/> <installed facet="jst.web" version="2.4"/> <installed facet="jst.java" version="1.4"/> </faceted-project>
Maven 2.x generated web application with JDK1.4 (see above), which is rather outdated, you may need to upgrade it to latest JDK version.
File : org.eclipse.wst.common.component
<project-modules id="moduleCoreId" project-version="2.0"> <wb-module deploy-name="mkyongweb-core"> <property name="context-root" value="mkyongweb-core"/> <wb-resource deploy-path="/" source-path="src/main/webapp"/> <property name="java-output-path" value="/target/classes"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/> </wb-module> </project-modules>
3. Import into Eclipse IDE
Now, you have everything what a Eclipse web application want, so, you can start import your Maven based web application into Eclipse IDE.
Steps :
In Eclipse IDE, menu bar , File -> Import… -> General -> Existing Projects into Workspace -> select root directory (select your project folder) -> Done.

Done.
Reference
- http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html
- http://maven.apache.org/plugins/maven-eclipse-plugin/wtp.html
- http://wiki.eclipse.org/WTP_FAQ#What_version_of_Eclipse_does_WTP_work_with.3F
- Unsupported WTP version: 1.5. This plugin currently supports only the following versions: 1.0 R7
- How to convert Java Project to Web Project in Eclipse
hello,
very useful article.
But i am facing one problem after importing my project in eclipse.
In Deployment Descriptor folder there is a file called Error pages. I am not getng the problem with this page. Because of this page error on project is shown. So i am not able to run the application.
Please help me as early as possible.
nice one
I think “mvn eclipse:eclipse -Dwtpversion=1.5″ is pretty outdated.
I found that the best way to work with Eclipse and Maven2 is to use the Eclipse’s m2eclipse plugin. http://m2eclipse.sonatype.org
See section on “Working With Eclipse and Dynamic Web Project” on this wiki:
http://code.google.com/p/jbosstown/wiki/GettingStartedWithMaven#Working_With_Eclipse_and_Dynamic_Web_Project
[...] Check here for detail about how to use Maven to create a Dynamic Web Project in Eclipse. [...]
Nice tutorials, I was wondering if you have some nice tutrial on Webservices.
thanks for the suggestion, will write some web services in future
Very useful info!
Any idea why generated classpath in the .classpath file does not include “src/main/java” and “src/test/java”?
In other words, it seems like the generated .classpath file does not include the 2 lines below:
Maven should be include those folders in Eclipse project .classpath, if your folder is follow Maven’s folder structure, Would you mind yo send me your project, in order to further study on it.