Tuesday, June 28, 2011

SPRING & MAVEN - Converting a Maven Webapp Project to work with Eclipse WTP Plugin

Steps

1. Create a maven-archetype-webapp project in eclipse.
2. Open Command prompt and go to project folder
3. Open the command prompt and go to project location

>cd c:\webprojects\MyPortal

4. Make sure the following environment variables are set in the command prompt.

4. Run the following two commands

>mvn eclipse:clean

>mvn eclipse:eclipse clean

This would remove the .project, .classpath settings

5. Run the command
>mvn eclipse:eclipse -Dwtpversion=2.0

This would create project facets for eclipse WTP plugin.

6. Refresh the project in eclipse
  • Update the Project Facets to use the latest JDK. By default the JDK 1.4 would be selected. It has to be updated to use a JDK version higher than JDK 1.4

7. Right Click Project -> Maven -> Disable Dependency Management.
8. Right Click Project -> Maven -> Enable Dependency Management.

This would enable Maven Dependencies to your project.

9. To add the Maven dependencies to the runtime environment (since they don't reside on WEB-INF/lib folder), Go to Project Properties, click on Java EE Module Dependencies and check the Maven Dependencies and click on Apply.


10. Include the Apache Runtime libraries to your classpath, Go to Project Build Path, in Libraries tab, click on Add Library, and then select Server Runtime and select Apache Tomcat.

If the Apache Tomcat server is not displayed in the selection pane, Create the Apache Server instance in Eclipse Servers tab and repeat the last procedure.

11. Replace the contents of  web.xml with the following details. This provides more schema details to the web-app root element.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
id="WebApp_ID" version="2.5">
</web-app>

With this your workspace is mavenized and ready to be running using the Eclipse WTP Plugin.

No comments:

Post a Comment