neděle 16. října 2011

Eclipse Indigo + Maven 3 + Tomcat debugging

I had a little hard time to see how to debug a Web project with Maven structure using Eclipse and build-in Tomcat debugging.

The problem is that Maven project has different structure thant Elicpses Dynamic Web Project, so finally eclipse does not know hot to package a WAR file and deploy it to the server.

Finally I found this blog, which explains the issue. This blog describes the situation when using Maven 2 and Eclipse Helios.

I use Maven 3 and Eclipse Indigo. When using Indigo, not all the steps described in the blog are needed (no changement of .project file needed). Basically you have to perform two steps.

1) Facets - change project nature. Go to the properties of the project and Project Facets and choose Dynamic Web Model. This step will change the structure of your project - add the WebContent folder.

2) Change the org.eclipse.wst.common.component file. This file is added when you have changed the project structure.

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="ProjectName">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/lib" source-path="/target/ProjecName/WEB-INF/lib"/>
<property name="context-root" value="ProjectName"/>
<property name="java-output-path" value="/ProjectName/target/classes"/>


What we need is to copy the everything we need into the WebContent directory. There are parts which you can copy directly from your project (jsp files, web.xml) and than parts which you have to copy from the Maven build output (libs, classes).

If you are lost, take a look at the mentioned blog.

Žádné komentáře: