Index: src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
===================================================================
--- src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java	(revision 586302)
+++ src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java	(working copy)
@@ -228,7 +228,7 @@
 
         MavenProject project = readProject( pom );
 
-        String outputDirPath = IdeUtils.getPluginSetting( project, "maven-eclipse-plugin", "outputDir", null );
+        String outputDirPath = IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
         File outputDir;
         File projectOutputDir = basedir;
 
@@ -296,7 +296,7 @@
 
         MavenProject project = readProject( pom );
 
-        String outputDirPath = IdeUtils.getPluginSetting( project, "maven-eclipse-plugin", "outputDir", null );
+        String outputDirPath = IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
         File outputDir;
         File projectOutputDir = basedir;
 
@@ -423,7 +423,7 @@
      * @param projectOutputDir
      * @throws IOException
      */
-    private void compareDirectoryContent( File basedir, File projectOutputDir, String additionalDir )
+    protected void compareDirectoryContent( File basedir, File projectOutputDir, String additionalDir )
         throws IOException
     {
         File expectedConfigDir = new File( basedir, "expected/" + additionalDir );
Index: src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java
===================================================================
--- src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java	(revision 586302)
+++ src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java	(working copy)
@@ -18,9 +18,16 @@
  */
 package org.apache.maven.plugin.eclipse;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
 import java.util.Properties;
 
 import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@@ -347,6 +354,54 @@
         testProject( "project-34" );
     }
     
+    public void testJeeSimple() throws Exception
+    {
+        testProject( "j2ee-simple" );
+
+        File basedir = getTestFile( "target/test-classes/projects/j2ee-simple" );
+        
+        checkContextRoot( basedir, "servlets/servlet", "ear", "servlet" );
+
+        
+    }
+    
+    public void testProject35() throws Exception
+    {
+        testProject( "project-35" );
+        
+        File basedir = getTestFile( "target/test-classes/projects/project-35" );
+        
+        checkContextRoot( basedir, "multymodule-war", "multymodule-ear", "/somethingVeryDifferent" );
+        
+    }
+    private void checkContextRoot( File basedir, String warModule, String earModule, String expectedContextRoot )
+        throws FileNotFoundException, XmlPullParserException, IOException
+    {
+        FileReader reader = new FileReader( new File(basedir ,warModule+"/.settings/org.eclipse.wst.common.component"));
+        Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
+        Xpp3Dom[] properties = warComponent.getChild( "wb-module" ).getChildren( "property" );
+        boolean contextRootAvaliable = false;
+        for ( int index = 0; index < properties.length; index++ )
+        {
+            if (properties[index].getAttribute( "name" ).equals( "context-root" )) {
+                assertEquals("Context root detection in org.eclipse.wst.common.component", expectedContextRoot, properties[index].getAttribute( "value" ) );
+                contextRootAvaliable=true;
+            }
+        }
+        assertTrue( "there must be a context root here", contextRootAvaliable );
+        
+        reader = new FileReader( new File(basedir ,earModule+"/target/eclipseEar/META-INF/application.xml"));
+        Xpp3Dom generatedApplicationXML = Xpp3DomBuilder.build( reader );
+  
+        Xpp3Dom [] modules = generatedApplicationXML.getChildren( "module" );
+        for ( int index = 0; index < modules.length; index++ )
+        {
+            if (modules[index].getChild( "web" )!=null) {
+                assertEquals("Context root detection in target/eclipseEar/META-INF/application.xml", expectedContextRoot, modules[index].getChild( "web" ).getChild( "context-root" ).getValue() );
+            }
+        }
+    }
+    
     /**
      * MECLIPSE-287 : dependencies with and without classifiers
      * MECLIPSE-151 : test jar source attachments
Index: src/test/java/org/apache/maven/plugin/eclipse/RadPluginTest.java
===================================================================
--- src/test/java/org/apache/maven/plugin/eclipse/RadPluginTest.java	(revision 586302)
+++ src/test/java/org/apache/maven/plugin/eclipse/RadPluginTest.java	(working copy)
@@ -84,7 +84,7 @@
 
         MavenProject project = readProject( pom0 );
 
-        String outputDirPath = IdeUtils.getPluginSetting( project, "maven-eclipse-plugin", "outputDir", null );
+        String outputDirPath = IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
         File outputDir;
 
         if ( outputDirPath == null )
@@ -145,7 +145,7 @@
 
         assertEquals( "project-rad-5_2.war", webappModule.getChild( "web" ).getChild( "web-uri" ).getValue() );
         assertEquals( "project-rad-5_2", webappModule.getChild( "web" ).getChild( "context-root" ).getValue() );
-        assertEquals( "project-rad-5_3.jar", ejbModule.getChild( "ejb" ).getValue() );
+        assertEquals( "project-rad-5_3.jar", ejbModule.getChild( Constants.PROJECT_PACKAGING_EJB ).getValue() );
 
         Xpp3Dom websettings =
             Xpp3DomBuilder.build( new FileReader( new File( basedir, "project-rad-2/.websettings" ) ) );
@@ -167,7 +167,7 @@
 
         MavenProject project = readProject( pom0 );
 
-        String outputDirPath = IdeUtils.getPluginSetting( project, "maven-eclipse-plugin", "outputDir", null );
+        String outputDirPath = IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
         File outputDir;
 
         if ( outputDirPath == null )
@@ -235,7 +235,7 @@
             }
             else if ( child.getAttribute( "id" ).startsWith( "EjbModule_" ) )
             {
-                assertEquals( "project-rad-5_3.jar", child.getChild( "ejb" ).getValue() );
+                assertEquals( "project-rad-5_3.jar", child.getChild( Constants.PROJECT_PACKAGING_EJB ).getValue() );
                 ejbVerified = true;
             }
         }
Index: src/test/resources/projects/project-34/pom.xml
===================================================================
--- src/test/resources/projects/project-34/pom.xml	(revision 586302)
+++ src/test/resources/projects/project-34/pom.xml	(working copy)
@@ -16,9 +16,9 @@
         <configuration>
           <workspace>${basedir}</workspace>
           <projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
-          <wtpContextName>${artifactId}-${version}</wtpContextName>
           <wtpmanifest>true</wtpmanifest>
           <wtpapplicationxml>true</wtpapplicationxml>
+          <wtpversion>2.0</wtpversion>
         </configuration>
       </plugin>
     </plugins>
Index: src/main/java/org/apache/maven/plugin/ide/IdeUtils.java
===================================================================
--- src/main/java/org/apache/maven/plugin/ide/IdeUtils.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/ide/IdeUtils.java	(working copy)
@@ -35,6 +35,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
@@ -80,7 +81,8 @@
      */
     private static final String PROPERTY_TARGET = "target"; //$NON-NLS-1$
 
-    public static String getCanonicalPath( File file ) throws MojoExecutionException
+    public static String getCanonicalPath( File file )
+        throws MojoExecutionException
     {
         try
         {
@@ -96,8 +98,7 @@
     /**
      * Returns a compiler plugin settings, considering also settings altered in plugin executions .
      * 
-     * @param project
-     *            maven project
+     * @param project maven project
      * @return option value (may be null)
      */
     public static String getCompilerPluginSetting( MavenProject project, String optionName )
@@ -116,8 +117,7 @@
      * Returns the source version configured for the compiler plugin. Returns the minimum version required to compile
      * both standard and test sources, if settings are different.
      * 
-     * @param project
-     *            maven project
+     * @param project maven project
      * @return java source version
      */
     public static String getCompilerSourceVersion( MavenProject project )
@@ -129,8 +129,7 @@
      * Returns the target version configured for the compiler plugin. Returns the minimum version required to compile
      * both standard and test sources, if settings are different.
      * 
-     * @param project
-     *            maven project
+     * @param project maven project
      * @return java target version
      */
     public static String getCompilerTargetVersion( MavenProject project )
@@ -141,12 +140,9 @@
     /**
      * Extracts the version of the first matching dependency in the given list.
      * 
-     * @param artifactIds
-     *            artifact names to compare against for extracting version
-     * @param dependencies
-     *            Collection of dependencies for our project
-     * @param len
-     *            expected length of the version sub-string
+     * @param artifactIds artifact names to compare against for extracting version
+     * @param dependencies Collection of dependencies for our project
+     * @param len expected length of the version sub-string
      * @return
      */
     public static String getDependencyVersion( String[] artifactIds, List dependencies, int len )
@@ -167,27 +163,80 @@
     }
 
     /**
+     * Search for a configuration setting of an other plugin for a configuration setting.
+     * 
      * @todo there should be a better way to do this
+     * @param project the current maven project to get the configuration from.
+     * @param pluginId the group id and artifact id of the plugin to search for
+     * @param optionName the option to get from the configuration
+     * @param defaultValue the default value if the configuration was not found
+     * @return the value of the option configured in the plugin configuration
      */
-    public static String getPluginSetting( MavenProject project, String artifactId, String optionName,
-                                           String defaultValue )
+    public static String getPluginSetting( MavenProject project, String pluginId, String optionName, String defaultValue )
     {
-        for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); )
+        Xpp3Dom dom = getPluginConfigurationDom( project, pluginId );
+        if ( dom != null && dom.getChild( optionName ) != null )
         {
-            Plugin plugin = (Plugin) it.next();
+            return dom.getChild( optionName ).getValue();
+        }
+        return defaultValue;
+    }
 
-            if ( plugin.getArtifactId().equals( artifactId ) )
+    /**
+     * Search for the configuration Xpp3 dom of an other plugin.
+     * 
+     * @todo there should be a better way to do this
+     * @param project the current maven project to get the configuration from.
+     * @param pluginId the group id and artifact id of the plugin to search for
+     * @return the value of the option configured in the plugin configuration
+     */
+    public static Xpp3Dom getPluginConfigurationDom( MavenProject project, String pluginId )
+    {
+
+        Plugin plugin = (org.apache.maven.model.Plugin) project.getBuild().getPluginsAsMap().get( pluginId );
+        if ( plugin != null )
+        {
+            return (Xpp3Dom) plugin.getConfiguration();
+        }
+        return null;
+    }
+
+    /**
+     * Search for the configuration Xpp3 dom of an other plugin.
+     * 
+     * @todo there should be a better way to do this
+     * @param project the current maven project to get the configuration from.
+     * @param artifactId the artifact id of the plugin to search for
+     * @return the value of the option configured in the plugin configuration
+     */
+    public static Xpp3Dom[] getPluginConfigurationDom( MavenProject project, String artifactId,
+                                                       String[] subConfiguration )
+    {
+        ArrayList configurationDomList = new ArrayList();
+        Xpp3Dom configuration = getPluginConfigurationDom( project, artifactId );
+        if ( configuration != null )
+        {
+            configurationDomList.add( configuration );
+            for ( int index = 0; !configurationDomList.isEmpty() && subConfiguration != null
+                && index < subConfiguration.length; index++ )
             {
-                Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration();
-
-                if ( o != null && o.getChild( optionName ) != null )
+                ArrayList newConfigurationDomList = new ArrayList();
+                for ( Iterator childElement = configurationDomList.iterator(); childElement.hasNext(); )
                 {
-                    return o.getChild( optionName ).getValue();
+                    Xpp3Dom child = (Xpp3Dom) childElement.next();
+                    Xpp3Dom[] deeperChild = child.getChildren( subConfiguration[index] );
+                    for ( int deeperIndex = 0; deeperIndex < deeperChild.length; deeperIndex++ )
+                    {
+                        if ( deeperChild[deeperIndex] != null )
+                        {
+                            newConfigurationDomList.add( deeperChild[deeperIndex] );
+                        }
+                    }
                 }
+                configurationDomList = newConfigurationDomList;
             }
         }
-
-        return defaultValue;
+        return (Xpp3Dom[]) configurationDomList.toArray( new Xpp3Dom[configurationDomList.size()] );
     }
 
     public static String getProjectName( String template, IdeDependency dep )
@@ -197,7 +246,7 @@
 
     /**
      * Use the project name template to create an eclipse project.
-     *  
+     * 
      * @param template Template for the project name
      * @param artifact the artifact to create the project name for
      * @return the created ide project name
@@ -206,7 +255,7 @@
     {
         return getProjectName( template, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
     }
-    
+
     public static String getProjectName( String template, MavenProject project )
     {
         return getProjectName( template, project.getGroupId(), project.getArtifactId(), project.getVersion() );
@@ -215,13 +264,13 @@
     public static String getProjectName( IdeDependency dep, boolean addVersionToProjectName )
     {
         return getProjectName( addVersionToProjectName ? PROJECT_NAME_WITH_VERSION_TEMPLATE
-                                                      : PROJECT_NAME_DEFAULT_TEMPLATE, dep );
+                        : PROJECT_NAME_DEFAULT_TEMPLATE, dep );
     }
 
     public static String getProjectName( MavenProject project, boolean addVersionToProjectName )
     {
         return getProjectName( addVersionToProjectName ? PROJECT_NAME_WITH_VERSION_TEMPLATE
-                                                      : PROJECT_NAME_DEFAULT_TEMPLATE, project );
+                        : PROJECT_NAME_DEFAULT_TEMPLATE, project );
     }
 
     public static Artifact resolveArtifactWithClassifier( String groupId, String artifactId, String version,
@@ -311,11 +360,11 @@
     public static String toRelativeAndFixSeparator( File basedir, File fileToAdd, boolean replaceSlashesWithDashes )
         throws MojoExecutionException
     {
-        if ( ! fileToAdd.isAbsolute() )
+        if ( !fileToAdd.isAbsolute() )
         {
             fileToAdd = new File( basedir, fileToAdd.getPath() );
         }
-        
+
         String basedirpath;
         String absolutePath;
 
@@ -351,8 +400,7 @@
     /**
      * Returns a compiler plugin settings from a list of plugins .
      * 
-     * @param project
-     *            maven project
+     * @param project maven project
      * @return option value (may be null)
      */
     private static String findCompilerPluginSettingInPlugins( List plugins, String optionName )
Index: src/main/java/org/apache/maven/plugin/ide/JeeUtils.java
===================================================================
--- src/main/java/org/apache/maven/plugin/ide/JeeUtils.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/ide/JeeUtils.java	(working copy)
@@ -25,6 +25,9 @@
 
 public class JeeUtils
 {
+    public static final String ARTIFACT_MAVEN_EAR_PLUGIN = "org.apache.maven.plugins:maven-ear-plugin"; //$NON-NLS-1$
+    public static final String ARTIFACT_MAVEN_WAR_PLUGIN = "org.apache.maven.plugins:maven-war-plugin"; //$NON-NLS-1$
+    
     private static final Map ejbMap = new HashMap();
 
     private static final Map jeeMap = new HashMap();
Index: src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java	(working copy)
@@ -60,6 +60,7 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.eclipse.Constants;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.logging.LogEnabled;
 import org.codehaus.plexus.logging.Logger;
@@ -713,7 +714,7 @@
             String type = dependency.getType();
             if ( type == null )
             {
-                type = "jar"; //$NON-NLS-1$
+                type = Constants.PROJECT_PACKAGING_JAR; //$NON-NLS-1$
             }
             String classifier = dependency.getClassifier();
             boolean optional = dependency.isOptional();
Index: src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java	(working copy)
@@ -410,7 +410,7 @@
         Artifact pomArtifact = artifactFactory.createArtifact( model.getGroupId(), model.getArtifactId(), model
             .getVersion(), null, "pom" );
         Artifact artifact = artifactFactory.createArtifact( model.getGroupId(), model.getArtifactId(), model
-            .getVersion(), null, "jar" );
+            .getVersion(), null, Constants.PROJECT_PACKAGING_JAR );
         try
         {
             pomFile = File.createTempFile( "pom-", ".xml" );
Index: src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java	(working copy)
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
@@ -49,21 +50,23 @@
 import org.apache.maven.plugin.ide.AbstractIdeSupportMojo;
 import org.apache.maven.plugin.ide.IdeDependency;
 import org.apache.maven.plugin.ide.IdeUtils;
+import org.apache.maven.plugin.ide.JeeUtils;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
  * Generates the following eclipse configuration files:
  * <ul>
- *   <li><code>.project</code> and <code>.classpath</code> files</li>
- *   <li><code>.setting/org.eclipse.jdt.core.prefs</code> with project specific compiler settings</li>
- *   <li>various configuration files for WTP (Web Tools Project), if the parameter <code>wtpversion</code> is set to a
- *   valid version (WTP configuration is not generated by default)</li>
+ * <li><code>.project</code> and <code>.classpath</code> files</li>
+ * <li><code>.setting/org.eclipse.jdt.core.prefs</code> with project specific compiler settings</li>
+ * <li>various configuration files for WTP (Web Tools Project), if the parameter <code>wtpversion</code> is set to a
+ * valid version (WTP configuration is not generated by default)</li>
  * </ul>
  * If this goal is run on a multiproject root, dependencies between modules will be configured as direct project
  * dependencies in Eclipse (unless <code>useProjectReferences</code> is set to <code>false</code>).
- *
+ * 
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
  * @version $Id$
@@ -76,13 +79,15 @@
 
     private static final String NATURE_WST_FACET_CORE_NATURE = "org.eclipse.wst.common.project.facet.core.nature"; //$NON-NLS-1$
 
-    private static final String BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER = "org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver"; //$NON-NLS-1$
+    private static final String BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER =
+        "org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver"; //$NON-NLS-1$
 
     private static final String BUILDER_WST_VALIDATION = "org.eclipse.wst.validation.validationbuilder"; //$NON-NLS-1$
 
     private static final String BUILDER_JDT_CORE_JAVA = "org.eclipse.jdt.core.javabuilder"; //$NON-NLS-1$
 
-    private static final String BUILDER_WST_COMPONENT_STRUCTURAL = "org.eclipse.wst.common.modulecore.ComponentStructuralBuilder"; //$NON-NLS-1$
+    private static final String BUILDER_WST_COMPONENT_STRUCTURAL =
+        "org.eclipse.wst.common.modulecore.ComponentStructuralBuilder"; //$NON-NLS-1$
 
     private static final String BUILDER_WST_FACET = "org.eclipse.wst.common.project.facet.core.builder"; //$NON-NLS-1$
 
@@ -102,8 +107,8 @@
 
     protected static final String REQUIRED_PLUGINS_CONTAINER = "org.eclipse.pde.core.requiredPlugins"; //$NON-NLS-1$
 
-    //  warning, order is important for binary search
-    public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "1.5", "R7", "none" }; //$NON-NLS-1$ //$NON-NLS-2$  //$NON-NLS-3$
+    // warning, order is important for binary search
+    public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "1.5", "2.0", "R7", "none" }; //$NON-NLS-1$ //$NON-NLS-2$  //$NON-NLS-3$
 
     /**
      * Constant for 'artifactId' element in POM.xml.
@@ -116,34 +121,33 @@
     private static final String POM_ELT_GROUP_ID = "groupId"; //$NON-NLS-1$
 
     /**
-     * List of eclipse project natures. By default the
-     * <code>org.eclipse.jdt.core.javanature</code> nature plus the needed WTP
-     * natures are added. Natures added using this property <strong>replace</strong> the default list.
-     *
+     * List of eclipse project natures. By default the <code>org.eclipse.jdt.core.javanature</code> nature plus the
+     * needed WTP natures are added. Natures added using this property <strong>replace</strong> the default list.
+     * 
      * <pre>
      * &lt;projectnatures&gt;
      *    &lt;projectnature&gt;org.eclipse.jdt.core.javanature&lt;/projectnature&gt;
      *    &lt;projectnature&gt;org.eclipse.wst.common.modulecore.ModuleCoreNature&lt;/projectnature&gt;
      * &lt;/projectnatures&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private List projectnatures;
 
     /**
      * List of eclipse project natures to be added to the default ones.
-     *
+     * 
      * <pre>
      * &lt;additionalProjectnatures&gt;
      *    &lt;projectnature&gt;org.springframework.ide.eclipse.core.springnature&lt;/projectnature&gt;
      * &lt;/additionalProjectnatures&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private List additionalProjectnatures;
-    
+
     /**
      * List of eclipse project facets to be added to the default ones.
      * 
@@ -152,21 +156,22 @@
      *    &lt;jst.jsf&gt;1.1&lt;jst.jsf/&gt;
      * &lt;/additionalProjectFacets&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private Map additionalProjectFacets;
 
     /**
-     * List of eclipse build commands. By default the <code>org.eclipse.jdt.core.javabuilder</code> builder plus the needed
-     * WTP builders are added.
-     *
-     * If you specify any configuration for this parameter, only those buildcommands specified will be used; the defaults
-     * won't be added. Use the <code>additionalBuildCommands</code> parameter for that.
-     *
+     * List of eclipse build commands. By default the <code>org.eclipse.jdt.core.javabuilder</code> builder plus the
+     * needed WTP builders are added.
+     * 
+     * If you specify any configuration for this parameter, only those buildcommands specified will be used; the
+     * defaults won't be added. Use the <code>additionalBuildCommands</code> parameter for that.
+     * 
      * Configuration example:
-     *
+     * 
      * Old style:
+     * 
      * <pre>
      * &lt;buildcommands&gt;
      *    &lt;buildcommand&gt;org.eclipse.wst.common.modulecore.ComponentStructuralBuilder&lt;/buildcommand&gt;
@@ -174,24 +179,26 @@
      *    &lt;buildcommand&gt;org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver&lt;/buildcommand&gt;
      * &lt;/buildcommands&gt;
      * </pre>
-     *
+     * 
      * For new style, see <code>additionalBuildCommands</code>.
-     *
+     * 
      * @parameter
      */
     private List buildcommands;
 
     /**
      * List of eclipse build commands to be added to the default ones.
-     *
+     * 
      * Old style:
+     * 
      * <pre>
      * &lt;additionalBuildcommands&gt;
      *    &lt;buildcommand&gt;org.springframework.ide.eclipse.core.springbuilder&lt;/buildcommand&gt;
      * &lt;/additionalBuildcommands&gt;
      * </pre>
-     *
+     * 
      * New style:
+     * 
      * <pre>
      * &lt;additionalBuildcommands&gt;
      *    &lt;buildCommand&gt;
@@ -203,19 +210,20 @@
      *    &lt;/buildCommand&gt;
      * &lt;/additionalBuildcommands&gt;
      * </pre>
-     *
-     * Note the difference between <code>build<strong>c</strong>ommand</code>
-     * and <code>build<strong>C</strong>ommand</code>.
-     *
+     * 
+     * Note the difference between <code>build<strong>c</strong>ommand</code> and
+     * <code>build<strong>C</strong>ommand</code>.
+     * 
      * You can mix and match old and new-style configuration entries.
-     *
+     * 
      * @parameter
      */
     private List additionalBuildcommands;
 
     /**
-     * List of container classpath entries. By default the <code>org.eclipse.jdt.launching.JRE_CONTAINER</code> classpath
-     * container is added. Configuration example:
+     * List of container classpath entries. By default the <code>org.eclipse.jdt.launching.JRE_CONTAINER</code>
+     * classpath container is added. Configuration example:
+     * 
      * <pre>
      * &lt;classpathContainers&gt;
      *    &lt;classpathContainer&gt;org.eclipse.jdt.launching.JRE_CONTAINER&lt;/classpathContainer&gt;
@@ -223,14 +231,14 @@
      *    &lt;classpathContainer&gt;org.eclipse.jst.j2ee.internal.web.container/artifact&lt;/classpathContainer&gt;
      * &lt;/classpathContainers&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private List classpathContainers;
 
     /**
      * Enables/disables the downloading of source attachments. Defaults to false. DEPRECATED - use downloadSources
-     *
+     * 
      * @parameter expression="${eclipse.downloadSources}"
      * @deprecated use downloadSources
      */
@@ -238,16 +246,15 @@
 
     /**
      * Eclipse workspace directory.
-     *
+     * 
      * @parameter expression="${eclipse.workspace}" alias="outputDir"
      */
     private File eclipseProjectDir;
 
     /**
-     * When set to false, the plugin will not create sub-projects and instead
-     * reference those sub-projects using the installed package in the local
-     * repository
-     *
+     * When set to false, the plugin will not create sub-projects and instead reference those sub-projects using the
+     * installed package in the local repository
+     * 
      * @parameter expression="${eclipse.useProjectReferences}" default-value="true"
      * @required
      */
@@ -255,41 +262,41 @@
 
     /**
      * The default output directory
-     *
-     * @parameter expression="${outputDirectory}" alias="outputDirectory" default-value="${project.build.outputDirectory}"
+     * 
+     * @parameter expression="${outputDirectory}" alias="outputDirectory"
+     *            default-value="${project.build.outputDirectory}"
      * @required
      */
     private File buildOutputDirectory;
 
     /**
-     * The version of WTP for which configuration files will be generated.
-     * The default value is "none" (don't generate WTP configuration), supported versions are "R7", "1.0", and "1.5"
-     *
+     * The version of WTP for which configuration files will be generated. The default value is "none" (don't generate
+     * WTP configuration), supported versions are "R7", "1.0", and "1.5"
+     * 
      * @parameter expression="${wtpversion}" default-value="none"
      */
     private String wtpversion;
-    
+
     /**
-    * JEE context name of the WTP module. ( ex. WEB context name ).
-    *
-    * @parameter expression="${wtpContextName}" default-value="${project.artifactId}"
-    */
+     * JEE context name of the WTP module. ( ex. WEB context name ).
+     * 
+     * @parameter expression="${wtpContextName}"
+     */
     private String wtpContextName;
-    
 
     /**
-     * Is it an PDE project? If yes, the plugin adds the necessary natures and build commands to
-     * the .project file. Additionally it copies all libraries to a project local directory and
-     * references them instead of referencing the files in the local Maven repository. It also
-     * ensured that the "Bundle-Classpath" in META-INF/MANIFEST.MF is synchronized.
-     *
+     * Is it an PDE project? If yes, the plugin adds the necessary natures and build commands to the .project file.
+     * Additionally it copies all libraries to a project local directory and references them instead of referencing the
+     * files in the local Maven repository. It also ensured that the "Bundle-Classpath" in META-INF/MANIFEST.MF is
+     * synchronized.
+     * 
      * @parameter expression="${eclipse.pde}" default-value="false"
      */
     private boolean pde;
 
     /**
      * The relative path of the manifest file
-     *
+     * 
      * @parameter expression="${eclipse.manifest}" default-value="${basedir}/META-INF/MANIFEST.MF"
      */
     private File manifest;
@@ -297,55 +304,54 @@
     /**
      * Allow to configure additional generic configuration files for eclipse that will be written out to disk when
      * running eclipse:eclipse. FOr each file you can specify the name and the text content.
-     *
+     * 
      * <pre>
      * &lt;additionalConfig&gt;
      *    &lt;file&gt;
      *      &lt;name&gt;.checkstyle&lt;/name&gt;
      *      &lt;content&gt;
-     *        &lt;![CDATA[&lt;fileset-config file-format-version="1.2.0" simple-config="true"&gt;
-     *          &lt;fileset name="all" enabled="true" check-config-name="acme corporate style" local="false"&gt;
-     *              &lt;file-match-pattern match-pattern="." include-pattern="true"/&gt;
+     *        &lt;![CDATA[&lt;fileset-config file-format-version=&quot;1.2.0&quot; simple-config=&quot;true&quot;&gt;
+     *          &lt;fileset name=&quot;all&quot; enabled=&quot;true&quot; check-config-name=&quot;acme corporate style&quot; local=&quot;false&quot;&gt;
+     *              &lt;file-match-pattern match-pattern=&quot;.&quot; include-pattern=&quot;true&quot;/&gt;
      *          &lt;/fileset&gt;
-     *          &lt;filter name="NonSrcDirs" enabled="true"/&gt;
+     *          &lt;filter name=&quot;NonSrcDirs&quot; enabled=&quot;true&quot;/&gt;
      *        &lt;/fileset-config&gt;]]&gt;
      *      &lt;/content&gt;
      *    &lt;/file&gt;
      * &lt;/additionalConfig&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private EclipseConfigFile[] additionalConfig;
-    
+
     /**
-     * If set to <code>true</code>, the version number of the artifact is appended
-     * to the name of the generated Eclipse project. See projectNameTemplate for other options.
+     * If set to <code>true</code>, the version number of the artifact is appended to the name of the generated
+     * Eclipse project. See projectNameTemplate for other options.
      * 
      * @parameter expression="${eclipse.addVersionToProjectName}" default-value="false"
      */
     private boolean addVersionToProjectName;
 
     /**
-     * If set to <code>true</code>, the groupId of the artifact is appended
-     * to the name of the generated Eclipse project. See projectNameTemplate for other options.
+     * If set to <code>true</code>, the groupId of the artifact is appended to the name of the generated Eclipse
+     * project. See projectNameTemplate for other options.
      * 
      * @parameter expression="${eclipse.addGroupIdToProjectName}" default-value="false"
      */
     private boolean addGroupIdToProjectName;
 
     /**
-     * Allows configuring the name of the eclipse projects. This property if set wins over
-     * addVersionToProjectName and addGroupIdToProjectName
+     * Allows configuring the name of the eclipse projects. This property if set wins over addVersionToProjectName and
+     * addGroupIdToProjectName
      * 
-     * You can use <code>[groupId]</code>, <code>[artifactId]</code> and <code>[version]</code>
-     * variables.
+     * You can use <code>[groupId]</code>, <code>[artifactId]</code> and <code>[version]</code> variables.
      * 
      * eg. <code>[groupId].[artifactId]-[version]</code>
      * 
      * @parameter expression="${eclipse.projectNameTemplate}"
      */
-    private String projectNameTemplate; 
+    private String projectNameTemplate;
 
     /**
      * Parsed wtp version.
@@ -363,19 +369,19 @@
      * @parameter expression="${eclipse.wtpmanifest}" default-value="false"
      */
     private boolean wtpmanifest;
-    
+
     /**
      * Must the application files be written for ear projects in a separate directory.
      * 
      * @parameter expression="${eclipse.wtpapplicationxml}" default-value="false"
      */
     private boolean wtpapplicationxml;
-    
+
     protected boolean isJavaProject()
     {
         return isJavaProject;
     }
-    
+
     protected boolean isPdeProject()
     {
         return pde;
@@ -383,6 +389,7 @@
 
     /**
      * Getter for <code>buildcommands</code>.
+     * 
      * @return Returns the buildcommands.
      */
     public List getBuildcommands()
@@ -392,6 +399,7 @@
 
     /**
      * Setter for <code>buildcommands</code>.
+     * 
      * @param buildcommands The buildcommands to set.
      */
     public void setBuildcommands( List buildcommands )
@@ -401,6 +409,7 @@
 
     /**
      * Getter for <code>buildOutputDirectory</code>.
+     * 
      * @return Returns the buildOutputDirectory.
      */
     public File getBuildOutputDirectory()
@@ -410,6 +419,7 @@
 
     /**
      * Setter for <code>buildOutputDirectory</code>.
+     * 
      * @param buildOutputDirectory The buildOutputDirectory to set.
      */
     public void setBuildOutputDirectory( File buildOutputDirectory )
@@ -419,6 +429,7 @@
 
     /**
      * Getter for <code>classpathContainers</code>.
+     * 
      * @return Returns the classpathContainers.
      */
     public List getClasspathContainers()
@@ -428,6 +439,7 @@
 
     /**
      * Setter for <code>classpathContainers</code>.
+     * 
      * @param classpathContainers The classpathContainers to set.
      */
     public void setClasspathContainers( List classpathContainers )
@@ -437,6 +449,7 @@
 
     /**
      * Getter for <code>eclipseProjectDir</code>.
+     * 
      * @return Returns the eclipseProjectDir.
      */
     public File getEclipseProjectDir()
@@ -446,6 +459,7 @@
 
     /**
      * Setter for <code>eclipseProjectDir</code>.
+     * 
      * @param eclipseProjectDir The eclipseProjectDir to set.
      */
     public void setEclipseProjectDir( File eclipseProjectDir )
@@ -455,6 +469,7 @@
 
     /**
      * Getter for <code>projectnatures</code>.
+     * 
      * @return Returns the projectnatures.
      */
     public List getProjectnatures()
@@ -464,6 +479,7 @@
 
     /**
      * Setter for <code>projectnatures</code>.
+     * 
      * @param projectnatures The projectnatures to set.
      */
     public void setProjectnatures( List projectnatures )
@@ -473,6 +489,7 @@
 
     /**
      * Getter for <code>useProjectReferences</code>.
+     * 
      * @return Returns the useProjectReferences.
      */
     public boolean getUseProjectReferences()
@@ -482,6 +499,7 @@
 
     /**
      * Setter for <code>useProjectReferences</code>.
+     * 
      * @param useProjectReferences The useProjectReferences to set.
      */
     public void setUseProjectReferences( boolean useProjectReferences )
@@ -491,6 +509,7 @@
 
     /**
      * Getter for <code>wtpversion</code>.
+     * 
      * @return Returns the wtpversion.
      */
     public String getWtpversion()
@@ -500,6 +519,7 @@
 
     /**
      * Setter for <code>wtpversion</code>.
+     * 
      * @param wtpversion The wtpversion to set.
      */
     public void setWtpversion( String wtpversion )
@@ -509,6 +529,7 @@
 
     /**
      * Getter for <code>additionalBuildcommands</code>.
+     * 
      * @return Returns the additionalBuildcommands.
      */
     public List getAdditionalBuildcommands()
@@ -518,6 +539,7 @@
 
     /**
      * Setter for <code>additionalBuildcommands</code>.
+     * 
      * @param additionalBuildcommands The additionalBuildcommands to set.
      */
     public void setAdditionalBuildcommands( List additionalBuildcommands )
@@ -527,6 +549,7 @@
 
     /**
      * Getter for <code>additionalProjectnatures</code>.
+     * 
      * @return Returns the additionalProjectnatures.
      */
     public List getAdditionalProjectnatures()
@@ -536,13 +559,14 @@
 
     /**
      * Setter for <code>additionalProjectnatures</code>.
+     * 
      * @param additionalProjectnatures The additionalProjectnatures to set.
      */
     public void setAdditionalProjectnatures( List additionalProjectnatures )
     {
         this.additionalProjectnatures = additionalProjectnatures;
     }
-    
+
     /**
      * Getter for <code>addVersionToProjectName</code>.
      */
@@ -550,7 +574,7 @@
     {
         return addVersionToProjectName;
     }
-    
+
     /**
      * Setter for <code>addVersionToProjectName</code>.
      */
@@ -566,7 +590,7 @@
     {
         return addGroupIdToProjectName;
     }
-    
+
     /**
      * Setter for <code>addGroupIdToProjectName</code>.
      */
@@ -602,9 +626,9 @@
 
         // ear projects don't contain java sources
         // pde projects are always java projects
-        isJavaProject = pde
-            || ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR
-                .equals( packaging ) );
+        isJavaProject =
+            pde
+                || ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) );
 
         setupExtras();
 
@@ -680,6 +704,10 @@
         {
             wtpVersionFloat = 1.5f;
         }
+        else if ( "2.0".equalsIgnoreCase( wtpversion ) ) //$NON-NLS-1$
+        {
+            wtpVersionFloat = 2.0f;
+        }
         if ( !"none".equalsIgnoreCase( wtpversion ) )
         {
             getLog().info( Messages.getString( "EclipsePlugin.wtpversion", wtpversion ) );
@@ -708,9 +736,10 @@
         // validate sanity of the current m2 project
         if ( Arrays.binarySearch( WTP_SUPPORTED_VERSIONS, wtpversion ) < 0 )
         {
-            throw new MojoExecutionException( Messages
-                .getString( "EclipsePlugin.unsupportedwtp", new Object[] { //$NON-NLS-1$
-                            wtpversion, StringUtils.join( WTP_SUPPORTED_VERSIONS, " " ) } ) ); //$NON-NLS-1$
+            throw new MojoExecutionException(
+                                              Messages.getString( "EclipsePlugin.unsupportedwtp", new Object[] { //$NON-NLS-1$
+                                                                  wtpversion,
+                                                                      StringUtils.join( WTP_SUPPORTED_VERSIONS, " " ) } ) ); //$NON-NLS-1$
         }
 
         assertNotEmpty( executedProject.getGroupId(), POM_ELT_GROUP_ID ); //$NON-NLS-1$
@@ -789,9 +818,9 @@
     {
         EclipseWriterConfig config = createEclipseWriterConfig( deps );
 
-        if (wtpmanifest && isJavaProject())
+        if ( wtpmanifest && isJavaProject() )
         {
-            EclipseManifestWriter.addManifestResource(getLog(), config);
+            EclipseManifestWriter.addManifestResource( getLog(), config );
         }
         // NOTE: This could change the config!
         writeExtraConfiguration( config );
@@ -809,7 +838,7 @@
         {
             new EclipseWtpComponentWriter().init( getLog(), config ).write();
         }
-        if ( wtpVersionFloat >= 1.5 )
+        if ( wtpVersionFloat == 1.5f || wtpVersionFloat == 2.0f )
         {
             new EclipseWtpComponent15Writer().init( getLog(), config ).write();
         }
@@ -820,12 +849,12 @@
         {
             new EclipseClasspathWriter().init( getLog(), config ).write();
         }
-        
-        if (wtpapplicationxml)
+
+        if ( wtpapplicationxml )
         {
-            new EclipseWtpApplicationXMLWriter().init(getLog(), config).write();
+            new EclipseWtpApplicationXMLWriter().init( getLog(), config ).write();
         }
-        
+
         if ( pde )
         {
             this.getLog().info( "The Maven Eclipse plugin runs in 'pde'-mode." );
@@ -884,9 +913,11 @@
         String projectName = IdeUtils.getProjectName( config.getProjectNameTemplate(), project );
 
         config.setEclipseProjectName( projectName );
-        
-        config.setWtpapplicationxml(wtpapplicationxml);
 
+        config.setWtpapplicationxml( wtpapplicationxml );
+
+        config.setWtpVersion( this.wtpVersionFloat );
+
         Set convertedBuildCommands = new LinkedHashSet();
 
         if ( buildcommands != null )
@@ -921,20 +952,78 @@
         config.setProjectFacets( additionalProjectFacets );
         config.setSourceDirs( sourceDirs );
         config.setAddVersionToProjectName( isAddVersionToProjectName() );
-        config.setContextName( this.wtpContextName );
-        config.setPackaging(this.packaging);
+        config.setPackaging( this.packaging );
 
+        collectWarContextRootsFromReactorEarConfiguration( config );
+
         return config;
     }
 
     /**
-     * Write any extra configuration information for the Eclipse project. This is an extension
-     * point, called before the main configurations are written.
-     * <br/>
-     * <b>
-     * NOTE: This could change the config!
-     * </b>
-     *
+     * If this is a war module peek into the reactor an search for an ear module that defines the context root of this
+     * module.
+     * 
+     * @param config config to save the context root.
+     */
+    private void collectWarContextRootsFromReactorEarConfiguration( EclipseWriterConfig config )
+    {
+        if ( reactorProjects != null && this.wtpContextName == null
+            && Constants.PROJECT_PACKAGING_WAR.equals( this.project.getPackaging() ) )
+        {
+            for ( Iterator iter = reactorProjects.iterator(); iter.hasNext(); )
+            {
+                MavenProject reactorProject = (MavenProject) iter.next();
+
+                if ( Constants.PROJECT_PACKAGING_EAR.equals( reactorProject.getPackaging() ) )
+                {
+                    Xpp3Dom[] warDefinitions =
+                        IdeUtils.getPluginConfigurationDom( reactorProject, JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
+                                                            new String[] { "modules", "webModule" } );
+                    for ( int index = 0; index < warDefinitions.length; index++ )
+                    {
+                        Xpp3Dom groupId = warDefinitions[index].getChild( "groupId" );
+                        Xpp3Dom artifactId = warDefinitions[index].getChild( "artifactId" );
+                        Xpp3Dom contextRoot = warDefinitions[index].getChild( "contextRoot" );
+                        if ( groupId != null && artifactId != null && contextRoot != null && groupId.getValue() != null
+                            && artifactId.getValue() != null && contextRoot.getValue() != null )
+                        {
+                            getLog().info(
+                                           "Found context root definition for " + groupId.getValue() + ":"
+                                               + artifactId.getValue() + " " + contextRoot.getValue() );
+                            if ( this.project.getArtifactId().equals( artifactId.getValue() )
+                                && this.project.getGroupId().equals( groupId.getValue() ) )
+                            {
+                                config.setContextName( contextRoot.getValue() );
+                            }
+                        }
+                        else
+                        {
+                            getLog().info(
+                                           "Found incomplete ear configuration in " + reactorProject.getGroupId() + ":"
+                                               + reactorProject.getGroupId() + " found "
+                                               + warDefinitions[index].toString() );
+                        }
+                    }
+                }
+            }
+        }
+        if ( config.getContextName() == null && Constants.PROJECT_PACKAGING_WAR.equals( this.project.getPackaging() ) )
+        {
+            if ( this.wtpContextName == null )
+            {
+                config.setContextName( this.project.getArtifactId() );
+            }
+            else
+            {
+                config.setContextName( this.wtpContextName );
+            }
+        }
+    }
+
+    /**
+     * Write any extra configuration information for the Eclipse project. This is an extension point, called before the
+     * main configurations are written. <br/> <b> NOTE: This could change the config! </b>
+     * 
      * @param config
      * @throws MojoExecutionException
      */
@@ -1021,7 +1110,8 @@
 
         if ( wtpVersionFloat == 0.7f )
         {
-            buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER ) ); // WTP 0.7 builder
+            buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER ) ); // WTP 0.7
+            // builder
         }
 
         if ( pde )
@@ -1048,15 +1138,17 @@
 
         // If using the standard output location, don't mix the test output into it.
         String testOutput = null;
-        boolean useStandardOutputDir = buildOutputDirectory
-            .equals( new File( project.getBuild().getOutputDirectory() ) );
+        boolean useStandardOutputDir =
+            buildOutputDirectory.equals( new File( project.getBuild().getOutputDirectory() ) );
         if ( useStandardOutputDir )
         {
-            getLog().debug("testOutput toRelativeAndFixSeparator " + projectBaseDir + " , " + project.getBuild()
-                    .getTestOutputDirectory());
-            testOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, new File( project.getBuild()
-                .getTestOutputDirectory() ), false );
-            getLog().debug("testOutput after toRelative : " + testOutput);
+            getLog().debug(
+                            "testOutput toRelativeAndFixSeparator " + projectBaseDir + " , "
+                                + project.getBuild().getTestOutputDirectory() );
+            testOutput =
+                IdeUtils.toRelativeAndFixSeparator( projectBaseDir,
+                                                    new File( project.getBuild().getTestOutputDirectory() ), false );
+            getLog().debug( "testOutput after toRelative : " + testOutput );
         }
 
         extractSourceDirs( directories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true, testOutput );
@@ -1078,8 +1170,9 @@
 
             if ( sourceRootFile.isDirectory() )
             {
-                String sourceRoot = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRootFile, !projectBaseDir
-                    .equals( basedir ) );
+                String sourceRoot =
+                    IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRootFile,
+                                                        !projectBaseDir.equals( basedir ) );
 
                 directories.add( new EclipseSourceDir( sourceRoot, output, false, test, null, null, false ) );
             }
@@ -1112,7 +1205,7 @@
             // TODO: figure out how to merge if the same dir is specified twice
             // with different in/exclude patterns.
 
-            File resourceDirectory = new File( /*basedir,*/resource.getDirectory() );
+            File resourceDirectory = new File( /* basedir, */resource.getDirectory() );
 
             if ( !resourceDirectory.exists() || !resourceDirectory.isDirectory() )
             {
@@ -1120,14 +1213,16 @@
                 continue;
             }
 
-            String resourceDir = IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, resourceDirectory,
-                                                                     !workspaceProjectBaseDir.equals( basedir ) );
+            String resourceDir =
+                IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, resourceDirectory,
+                                                    !workspaceProjectBaseDir.equals( basedir ) );
             String thisOutput = output;
             if ( thisOutput != null )
             {
                 // sometimes thisOutput is already an absolute path
                 File outputFile = new File( thisOutput );
-                if(!outputFile.isAbsolute()){
+                if ( !outputFile.isAbsolute() )
+                {
                     outputFile = new File( workspaceProjectBaseDir, thisOutput );
                 }
                 // create output dir if it doesn't exist
@@ -1141,13 +1236,14 @@
                 }
 
                 getLog().debug(
-                        "Making relative and fixing separator: { " + workspaceProjectBaseDir + ", " +  outputFile + ", false }." );
+                                "Making relative and fixing separator: { " + workspaceProjectBaseDir + ", "
+                                    + outputFile + ", false }." );
                 thisOutput = IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, outputFile, false );
             }
 
             getLog().debug(
-                            "Adding eclipse source dir: { " + resourceDir + ", " + thisOutput + ", true, " + test + ", "
-                                + includePattern + ", " + excludePattern + " }." );
+                            "Adding eclipse source dir: { " + resourceDir + ", " + thisOutput + ", true, " + test
+                                + ", " + includePattern + ", " + excludePattern + " }." );
 
             directories.add( new EclipseSourceDir( resourceDir, thisOutput, true, test, includePattern, excludePattern,
                                                    resource.isFiltering() ) );
@@ -1158,8 +1254,7 @@
      * Calculate the project name template from the fields {@link #projectNameTemplate},
      * {@link #addVersionToProjectName} and {@link #addGroupIdToProjectName}
      * 
-     * @return the project name template that should be used after considering the plugin
-     *         configuration
+     * @return the project name template that should be used after considering the plugin configuration
      */
     private String calculateProjectNameTemplate()
     {
@@ -1191,7 +1286,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getProjectNameForArifact(Artifact artifact) {
-        return IdeUtils.getProjectName(calculateProjectNameTemplate(), artifact);
+    public String getProjectNameForArifact( Artifact artifact )
+    {
+        return IdeUtils.getProjectName( calculateProjectNameTemplate(), artifact );
     }
 }
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java	(working copy)
@@ -362,6 +362,8 @@
         String kind;
         String sourcepath = null;
         String javadocpath = null;
+        
+        boolean attributeElemOpen = false;
 
         if ( dep.isReferencedProject() && !config.isPde() )
         {
@@ -463,16 +465,36 @@
 
         if ( javadocpath != null )
         {
-            writer.startElement( "attributes" ); //$NON-NLS-1$
+        	if (!attributeElemOpen) {
+        		writer.startElement( "attributes" ); //$NON-NLS-1$
+        		attributeElemOpen = true;
+        	}
 
             writer.startElement( "attribute" ); //$NON-NLS-1$
             writer.addAttribute( "value", "jar:file:/" + javadocpath + "!/" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
             writer.addAttribute( "name", "javadoc_location" ); //$NON-NLS-1$ //$NON-NLS-2$
             writer.endElement();
 
+        }
+        
+        if ( config.getWtpapplicationxml() && kind.equals( ATTR_VAR ) 
+             && !dep.isTestDependency() && !dep.isProvided() && !dep.isSystemScoped())
+        {
+        	if (!attributeElemOpen) {
+        		writer.startElement( "attributes" ); //$NON-NLS-1$
+        		attributeElemOpen = true;
+        	}
+
+            writer.startElement( "attribute" ); //$NON-NLS-1$
+            writer.addAttribute( "value", "/WEB-INF/lib" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( "name", "org.eclipse.jst.component.dependency" ); //$NON-NLS-1$ //$NON-NLS-2$
             writer.endElement();
+
         }
 
+        if (attributeElemOpen) {
+        	writer.endElement();
+        }
         writer.endElement();
 
     }
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadApplicationXMLWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadApplicationXMLWriter.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadApplicationXMLWriter.java	(working copy)
@@ -32,6 +32,7 @@
 import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter;
 import org.apache.maven.plugin.eclipse.writers.wtp.AbstractWtpResourceWriter;
 import org.apache.maven.plugin.ide.IdeDependency;
+import org.apache.maven.plugin.ide.IdeUtils;
 import org.apache.maven.plugin.ide.JeeUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
@@ -47,7 +48,8 @@
  * 
  * @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven </a>
  */
-public class RadApplicationXMLWriter extends AbstractEclipseWriter
+public class RadApplicationXMLWriter
+    extends AbstractEclipseWriter
 {
 
     private static final String APPLICATION_XML_APPLICATION = "application";
@@ -118,16 +120,13 @@
      * write the application.xml and the .modulemaps file to the META-INF directory.
      * 
      * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File)
-     * @param sourceDirs
-     *            all eclipse source directorys
-     * @param localRepository
-     *            the local reposetory
-     * @param buildOutputDirectory
-     *            build output directory (target)
-     * @throws MojoExecutionException
-     *             when writing the config files was not possible
+     * @param sourceDirs all eclipse source directorys
+     * @param localRepository the local reposetory
+     * @param buildOutputDirectory build output directory (target)
+     * @throws MojoExecutionException when writing the config files was not possible
      */
-    public void write() throws MojoExecutionException
+    public void write()
+        throws MojoExecutionException
     {
         String packaging = config.getPackaging();
         if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) )
@@ -150,18 +149,9 @@
             }
             this.modulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
 
-            try
-            {
-                this.webModulesFromPoms =
-                    ( (Xpp3Dom) ( (org.apache.maven.model.Plugin) config.getProject().getBuild().getPluginsAsMap().get(
-                                                                                                                        "org.apache.maven.plugins:maven-ear-plugin" ) ).getConfiguration() ).getChild(
-                                                                                                                                                                                                       "modules" ).getChildren(
-                                                                                                                                                                                                                                "webModule" );
-            }
-            catch ( java.lang.NullPointerException ex )
-            {
-                this.webModulesFromPoms = new Xpp3Dom[0];
-            }
+            this.webModulesFromPoms =
+                IdeUtils.getPluginConfigurationDom( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
+                                                    new String[] { "modules", "webModule" } );
 
             IdeDependency[] deps = config.getDeps();
             for ( int index = 0; index < deps.length; index++ )
@@ -193,7 +183,7 @@
         result.setAttribute( XMLNS_XSI, "http://www.w3.org/2001/XMLSchema-instance" );
         result.setAttribute( XMLNS_SCHEMA_LOCATION,
                              "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_"
-                                             + j2eeVersion.charAt( 0 ) + "_" + j2eeVersion.charAt( 2 ) + ".xsd" );
+                                 + j2eeVersion.charAt( 0 ) + "_" + j2eeVersion.charAt( 2 ) + ".xsd" );
         result.addChild( new Xpp3Dom( APPLICATION_XML_DESCRIPTION ) );
         Xpp3Dom name = new Xpp3Dom( APPLICATION_XML_DISPLAY_NAME );
         name.setValue( config.getProject().getArtifactId() );
@@ -221,10 +211,8 @@
      * find an existing module entry in the application.xml file by looking up the id in the modulemaps file and then
      * using that to locate the entry in the application.xml file.
      * 
-     * @param applicationXmlDom
-     *            application.xml dom tree
-     * @param mapping
-     *            .modulemaps dom tree
+     * @param applicationXmlDom application.xml dom tree
+     * @param mapping .modulemaps dom tree
      * @return dom tree representing the module
      */
     private Xpp3Dom findModuleInApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom mapping )
@@ -245,10 +233,8 @@
     /**
      * find an artifact in the modulemaps dom tree, if it is missing create a new entry in the modulemaps dom tree.
      * 
-     * @param dependency
-     *            dependency to find
-     * @param modulemapXmlDom
-     *            dom-tree of modulemaps
+     * @param dependency dependency to find
+     * @param modulemapXmlDom dom-tree of modulemaps
      * @return dom-tree representing the artifact
      */
     private Xpp3Dom findOrCreateArtifact( IdeDependency dependency, Xpp3Dom modulemapXmlDom )
@@ -260,21 +246,21 @@
             if ( children[index].getAttribute( MODULEMAPS_PROJECT_NAME ).equals( dependency.getArtifactId() ) )
             {
                 if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB )
-                                && children[index].getName().equals( MODULEMAPS_MAPPINGS )
-                                && children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
-                                                                                                                       MODULEMAPS_APPLICATION_EJB_MODULE ) )
+                    && children[index].getName().equals( MODULEMAPS_MAPPINGS )
+                    && children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
+                                                                                                           MODULEMAPS_APPLICATION_EJB_MODULE ) )
                 {
                     return children[index];
                 }
                 else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR )
-                                && children[index].getName().equals( MODULEMAPS_MAPPINGS )
-                                && children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
-                                                                                                                       MODULEMAPS_APPLICATION_WEB_MODULE ) )
+                    && children[index].getName().equals( MODULEMAPS_MAPPINGS )
+                    && children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
+                                                                                                           MODULEMAPS_APPLICATION_WEB_MODULE ) )
                 {
                     return children[index];
                 }
                 else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_JAR )
-                                && children[index].getName().equals( MODULEMAPS_UTILITY_JARMAPPINGS ) )
+                    && children[index].getName().equals( MODULEMAPS_UTILITY_JARMAPPINGS ) )
                 {
                     return children[index];
                 }
@@ -326,8 +312,7 @@
     /**
      * get the id from the href of a modulemap.
      * 
-     * @param mapping
-     *            the dom-tree of modulemaps
+     * @param mapping the dom-tree of modulemaps
      * @return module identifier
      */
     private String getIdFromMapping( Xpp3Dom mapping )
@@ -344,8 +329,7 @@
     /**
      * mark the domtree entry as handled (all not handled ones will be deleted).
      * 
-     * @param xpp3Dom
-     *            dom element to mark handled
+     * @param xpp3Dom dom element to mark handled
      */
     private void handled( Xpp3Dom xpp3Dom )
     {
@@ -368,8 +352,7 @@
     /**
      * read an xml file (application.xml or .modulemaps).
      * 
-     * @param xmlFile
-     *            an xmlfile
+     * @param xmlFile an xmlfile
      * @return dom-tree representing the file contents
      */
     private Xpp3Dom readXMLFile( File xmlFile )
@@ -395,10 +378,8 @@
     /**
      * delete all unused entries from the dom-trees.
      * 
-     * @param applicationXmlDom
-     *            dom-tree of application.xml
-     * @param modulemapsXmlDom
-     *            dom-tree of modulemaps
+     * @param applicationXmlDom dom-tree of application.xml
+     * @param modulemapsXmlDom dom-tree of modulemaps
      */
     private void removeUnusedEntries( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapsXmlDom )
     {
@@ -410,7 +391,7 @@
                 for ( int newIndex = 0; newIndex < newModulemapsXmlDomChildren.length; newIndex++ )
                 {
                     if ( ( newModulemapsXmlDomChildren[newIndex] != null )
-                                    && ( newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index] ) )
+                        && ( newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index] ) )
                     {
                         modulemapsXmlDom.removeChild( newIndex );
                         break;
@@ -440,12 +421,9 @@
      * go in both files all others only in the modulemaps files. Webapplications contextroots are corrected to the
      * contextRoot specified in the pom.
      * 
-     * @param applicationXmlDom
-     *            dom-tree of application.xml
-     * @param modulemapXmlDom
-     *            dom-tree of modulemaps
-     * @param dependency
-     *            the eclipse dependency to handle
+     * @param applicationXmlDom dom-tree of application.xml
+     * @param modulemapXmlDom dom-tree of modulemaps
+     * @param dependency the eclipse dependency to handle
      */
     private void updateApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapXmlDom, IdeDependency dependency )
     {
@@ -497,7 +475,7 @@
                     handled( module );
                     module.getChild( APPLICATION_XML_WEB ).getChild( APPLICATION_XML_WEB_URI ).setValue(
                                                                                                          dependency.getArtifactId()
-                                                                                                                         + ".war" );
+                                                                                                             + ".war" );
                     module.getChild( APPLICATION_XML_WEB ).getChild( APPLICATION_XML_CONTEXT_ROOT ).setValue(
                                                                                                               contextRootInPom );
                 }
@@ -508,8 +486,7 @@
     /**
      * Find the contextRoot specified in the pom and convert it into contectroot for the application.xml.
      * 
-     * @param artifactId
-     *            the artifactid to search
+     * @param artifactId the artifactid to search
      * @return string with the context root
      */
     private String getContextRootFor( String artifactId )
@@ -525,14 +502,12 @@
     /**
      * write back a domtree to a xmlfile and use the pretty print for it so that it is human readable.
      * 
-     * @param xmlFile
-     *            file to write to
-     * @param xmlDomTree
-     *            dom-tree to write
-     * @throws MojoExecutionException
-     *             if the file could not be written
+     * @param xmlFile file to write to
+     * @param xmlDomTree dom-tree to write
+     * @throws MojoExecutionException if the file could not be written
      */
-    private void writePrettyXmlFile( File xmlFile, Xpp3Dom xmlDomTree ) throws MojoExecutionException
+    private void writePrettyXmlFile( File xmlFile, Xpp3Dom xmlDomTree )
+        throws MojoExecutionException
     {
         Xpp3Dom original = readXMLFile( xmlFile );
         if ( original != null && original.equals( xmlDomTree ) )
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadManifestWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadManifestWriter.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadManifestWriter.java	(working copy)
@@ -72,7 +72,7 @@
     {
         String metaInfBaseDirectory = null;
 
-        if ( config.getProject().equals( Constants.PROJECT_PACKAGING_WAR ) )
+        if ( config.getProject().getPackaging().equals( Constants.PROJECT_PACKAGING_WAR ) )
         {
             metaInfBaseDirectory = config.getProject().getBasedir().getAbsolutePath() + File.separatorChar
                 + WEBAPP_RESOURCE_DIR;
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java	(working copy)
@@ -134,6 +134,11 @@
     private boolean wtpapplicationxml;
     
     /**
+     * @see  EclipsePlugin#getWtpversion()
+     */
+    private float wtpVersion;
+    
+    /**
      * Getter for <code>deps</code>.
      * @return Returns the deps.
      */
@@ -439,13 +444,40 @@
         this.packaging = packaging;
     }
     
+    /**
+     * Getter for <code>wtpapplicationxml</code>.
+     * @return Returns the wtpapplicationxml.
+     */
     public boolean getWtpapplicationxml()
     {
          return this.wtpapplicationxml;
     }
-    
+
+    /**
+     * Setter for <code>buildCommands</code>.
+     * @param buildCommands The buildCommands to set.
+     */
     public void setWtpapplicationxml( boolean wtpapplicationxml )
     {
         this.wtpapplicationxml = wtpapplicationxml;
-    }    
+    }
+
+    /**
+     * Getter for <code>wtpVersion</code>.
+     * @return Returns the wtpVersion.
+     */
+    public float getWtpVersion()
+    {
+        return wtpVersion;
+    }
+
+    /**
+     * Setter for <code>wtpVersion</code>.
+     * @param wtpVersion The wtpVersion to set.
+     */
+    public void setWtpVersion( float wtpVersion )
+    {
+        this.wtpVersion = wtpVersion;
+    }
+
 }
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponentWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponentWriter.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponentWriter.java	(working copy)
@@ -20,9 +20,11 @@
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
 import org.apache.maven.plugin.eclipse.Messages;
 import org.apache.maven.plugin.ide.IdeUtils;
+import org.apache.maven.plugin.ide.JeeUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 import org.codehaus.plexus.util.xml.XMLWriter;
@@ -128,11 +130,11 @@
         // deploy-path is "/" for utility and ejb projects, "/WEB-INF/classes" for webapps
         String target = "/"; //$NON-NLS-1$
 
-        if ( "war".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+        if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
         {
             target = "/WEB-INF/classes"; //$NON-NLS-1$
 
-            File warSourceDirectory = new File( IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_WAR_PLUGIN,
+            File warSourceDirectory = new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
                                                                    "warSourceDirectory", //$NON-NLS-1$
                                                                    config.getProject().getBasedir()+"/src/main/webapp" ) ); //$NON-NLS-1$
             
@@ -152,12 +154,12 @@
             writer.endElement(); // property
 
         }
-        else if ( "ear".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+        else if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
         {
         	
         	String defaultApplicationXML = config.getWtpapplicationxml()?"/target/eclipseEar":"/src/main/application";
         	
-            String earSourceDirectory = IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_EAR_PLUGIN,
+            String earSourceDirectory = IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
                                                                    "earSourceDirectory", //$NON-NLS-1$
                                                                    config.getProject().getBasedir()+defaultApplicationXML); //$NON-NLS-1$
             writer.startElement( ELT_WB_RESOURCE );
@@ -167,7 +169,7 @@
             writer.endElement();
         }
 
-        if ( "war".equalsIgnoreCase( packaging ) || "ear".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$ //$NON-NLS-2$
+        if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) || Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$ //$NON-NLS-2$
         {
             // write out the dependencies.
             writeWarOrEarResources( writer, config.getProject(), localRepository );
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpApplicationXMLWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpApplicationXMLWriter.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpApplicationXMLWriter.java	(working copy)
@@ -8,8 +8,11 @@
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
 import org.apache.maven.plugin.ide.IdeDependency;
+import org.apache.maven.plugin.ide.IdeUtils;
+import org.apache.maven.plugin.ide.JeeUtils;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
@@ -19,496 +22,591 @@
 import org.codehaus.plexus.util.xml.Xpp3DomWriter;
 
 /**
- * This writer creates the application.xml and the .modulemaps files for RAD6
- * the the META-INF directory in the project root. this is where RAD6 requires
- * the files to be. These will be independent of the real application.xml witch
- * will be generated the stad. maven way.
+ * This writer creates the application.xml and the .modulemaps files for RAD6 the the META-INF directory in the project
+ * root. this is where RAD6 requires the files to be. These will be independent of the real application.xml witch will
+ * be generated the stad. maven way.
  * 
  * @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven</a>
  */
-public class EclipseWtpApplicationXMLWriter extends AbstractWtpResourceWriter {
-	private static final String APPLICATION_XML_APPLICATION = "application";
+public class EclipseWtpApplicationXMLWriter
+    extends AbstractWtpResourceWriter
+{
 
-	private static final String APPLICATION_XML_CONTEXT_ROOT = "context-root";
+    private static final String APPLICATION_XML_APPLICATION = "application";
 
-	private static final String APPLICATION_XML_DESCRIPTION = "description";
+    private static final String APPLICATION_XML_CONTEXT_ROOT = "context-root";
 
-	private static final String APPLICATION_XML_DISPLAY_NAME = "display-name";
+    private static final String APPLICATION_XML_DESCRIPTION = "description";
 
-	private static final String APPLICATION_XML_FILENAME = "application.xml";
+    private static final String APPLICATION_XML_DISPLAY_NAME = "display-name";
 
-	private static final String APPLICATION_XML_MODULE = "module";
+    private static final String APPLICATION_XML_FILENAME = "application.xml";
 
-	private static final String APPLICATION_XML_WEB = "web";
+    private static final String APPLICATION_XML_MODULE = "module";
 
-	private static final String APPLICATION_XML_WEB_URI = "web-uri";
+    private static final String APPLICATION_XML_WEB = "web";
 
-	private static final String HREF = "href";
+    private static final String APPLICATION_XML_WEB_URI = "web-uri";
 
-	private static final String ID = "id";
+    private static final String HREF = "href";
 
-	private static final String MODULEMAP_EARPROJECT_MAP = "modulemap:EARProjectMap";
+    private static final String ID = "id";
 
-	private static final String MODULEMAPS_APPLICATION_EJB_MODULE = "application:EjbModule";
+    private static final String MODULEMAP_EARPROJECT_MAP = "modulemap:EARProjectMap";
 
-	private static final String MODULEMAPS_APPLICATION_WEB_MODULE = "application:WebModule";
+    private static final String MODULEMAPS_APPLICATION_EJB_MODULE = "application:EjbModule";
 
-	private static final String MODULEMAPS_FILENAME = ".modulemaps";
+    private static final String MODULEMAPS_APPLICATION_WEB_MODULE = "application:WebModule";
 
-	private static final String MODULEMAPS_MAPPINGS = "mappings";
+    private static final String MODULEMAPS_FILENAME = ".modulemaps";
 
-	private static final String MODULEMAPS_PROJECT_NAME = "projectName";
+    private static final String MODULEMAPS_MAPPINGS = "mappings";
 
-	private static final String MODULEMAPS_UTILITY_JARMAPPINGS = "utilityJARMappings";
+    private static final String MODULEMAPS_PROJECT_NAME = "projectName";
 
-	private static final String URI = "uri";
+    private static final String MODULEMAPS_UTILITY_JARMAPPINGS = "utilityJARMappings";
 
-	private static final String VERSION = "version";
+    private static final String URI = "uri";
 
-	private static final String XMI_ID = "xmi:id";
+    private static final String VERSION = "version";
 
-	private static final String XMI_TYPE = "xmi:type";
+    private static final String XMI_ID = "xmi:id";
 
-	private static final String XMI_VERSION = "xmi:version";
+    private static final String XMI_TYPE = "xmi:type";
 
-	private static final String XMLNS = "xmlns";
+    private static final String XMI_VERSION = "xmi:version";
 
-	private static final String XMLNS_APPLICATION = "xmlns:application";
+    private static final String XMLNS = "xmlns";
 
-	private static final String XMLNS_MODULEMAP = "xmlns:modulemap";
+    private static final String XMLNS_APPLICATION = "xmlns:application";
 
-	private static final String XMLNS_SCHEMA_LOCATION = "xmlns:schemaLocation";
+    private static final String XMLNS_MODULEMAP = "xmlns:modulemap";
 
-	private static final String XMLNS_XMI = "xmlns:xmi";
+    private static final String XMLNS_SCHEMA_LOCATION = "xmlns:schemaLocation";
 
-	private static final String XMLNS_XSI = "xmlns:xsi";
+    private static final String XMLNS_XMI = "xmlns:xmi";
 
-	private Xpp3Dom[] applicationXmlDomChildren;
+    private static final String XMLNS_XSI = "xmlns:xsi";
 
-	private Xpp3Dom[] modulemapsXmlDomChildren;
+    private Xpp3Dom[] applicationXmlDomChildren;
 
-	private Xpp3Dom[] webModulesFromPoms;
+    private Xpp3Dom[] modulemapsXmlDomChildren;
 
-	/**
-	 * write the application.xml and the .modulemaps file to the META-INF
-	 * directory.
-	 * 
-	 * @see AbstractWtpResourceWriter#write(EclipseSourceDir[],
-	 *      ArtifactRepository, File)
-	 * @throws MojoExecutionException
-	 *             when writing the config files was not possible
-	 */
-	public void write() throws MojoExecutionException {
-		String packaging = this.config.getProject().getPackaging();
-		if ("ear".equalsIgnoreCase(packaging)) {
-			File applicationXmlFile = new File(this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" + File.separator + "META-INF" + File.separator
-					+ EclipseWtpApplicationXMLWriter.APPLICATION_XML_FILENAME);
-			// create the directory structiure for eclipse deployment
-			applicationXmlFile.getParentFile().mkdirs();
-			// copy all deployment files to the eclipse deployment
-			copyApplicationFiles();
-			// delete any existing application.xml so that it will be
-			// overwritten.
-			applicationXmlFile.delete();
+    private Xpp3Dom[] webModulesFromPoms;
 
-			Xpp3Dom applicationXmlDom = readXMLFile(applicationXmlFile);
-			if (applicationXmlDom == null) {
-				applicationXmlDom = createNewApplicationXml();
-			}
-			this.applicationXmlDomChildren = applicationXmlDom.getChildren(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
+    /**
+     * write the application.xml and the .modulemaps file to the META-INF directory.
+     * 
+     * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File)
+     * @throws MojoExecutionException when writing the config files was not possible
+     */
+    public void write()
+        throws MojoExecutionException
+    {
+        String packaging = this.config.getProject().getPackaging();
+        if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) )
+        {
+            File applicationXmlFile =
+                new File( this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar"
+                    + File.separator + "META-INF" + File.separator
+                    + EclipseWtpApplicationXMLWriter.APPLICATION_XML_FILENAME );
+            // create the directory structiure for eclipse deployment
+            applicationXmlFile.getParentFile().mkdirs();
+            // copy all deployment files to the eclipse deployment
+            copyApplicationFiles();
+            // delete any existing application.xml so that it will be
+            // overwritten.
+            applicationXmlFile.delete();
 
-			File modulemapsXmlFile = new File(this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" + File.separator + "META-INF" + File.separator
-					+ EclipseWtpApplicationXMLWriter.MODULEMAPS_FILENAME);
-			Xpp3Dom modulemapsXmlDom = readXMLFile(modulemapsXmlFile);
-			if (modulemapsXmlDom == null) {
-				modulemapsXmlDom = createNewModulemaps();
-			}
-			this.modulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
+            Xpp3Dom applicationXmlDom = readXMLFile( applicationXmlFile );
+            if ( applicationXmlDom == null )
+            {
+                applicationXmlDom = createNewApplicationXml();
+            }
+            this.applicationXmlDomChildren =
+                applicationXmlDom.getChildren( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
 
-			this.webModulesFromPoms = ((Xpp3Dom) ((org.apache.maven.model.Plugin) this.config.getProject().getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-ear-plugin"))
-					.getConfiguration()).getChild("modules").getChildren("webModule");
+            File modulemapsXmlFile =
+                new File( this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar"
+                    + File.separator + "META-INF" + File.separator + EclipseWtpApplicationXMLWriter.MODULEMAPS_FILENAME );
+            Xpp3Dom modulemapsXmlDom = readXMLFile( modulemapsXmlFile );
+            if ( modulemapsXmlDom == null )
+            {
+                modulemapsXmlDom = createNewModulemaps();
+            }
+            this.modulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
 
-			IdeDependency[] deps = this.config.getDeps();
-			for (int index = 0; index < deps.length; index++) {
-				updateApplicationXml(applicationXmlDom, modulemapsXmlDom, deps[index]);
-			}
+            this.webModulesFromPoms =
+                IdeUtils.getPluginConfigurationDom( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
+                                                    new String[] { "modules", "webModule" } );
 
-			removeUnusedEntries(applicationXmlDom, modulemapsXmlDom);
+            IdeDependency[] deps = this.config.getDeps();
+            for ( int index = 0; index < deps.length; index++ )
+            {
+                updateApplicationXml( applicationXmlDom, modulemapsXmlDom, deps[index] );
+            }
 
-			writePrettyXmlFile(applicationXmlFile, applicationXmlDom);
-			writePrettyXmlFile(modulemapsXmlFile, modulemapsXmlDom);
-		}
-	}
+            removeUnusedEntries( applicationXmlDom, modulemapsXmlDom );
 
-	/**
-	 * Copy all files from application directory to the target eclipseEar
-	 * directory.
-	 * 
-	 * @throws MojoExecutionException
-	 *             wenn an error occures during file copieing
-	 */
-	private void copyApplicationFiles() throws MojoExecutionException {
-		try {
-			File applicationDirectory = new File(this.config.getEclipseProjectDirectory(), "src" + File.separator + "main" + File.separator + "application");
-			File eclipseApplicationDirectory = new File(this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar");
-			copyDirectoryStructure(applicationDirectory, eclipseApplicationDirectory);
-		} catch (IOException e) {
-			throw new MojoExecutionException("could not copy files the the eclipseEar directory", e);
-		}
-	}
+            writePrettyXmlFile( applicationXmlFile, applicationXmlDom );
+            writePrettyXmlFile( modulemapsXmlFile, modulemapsXmlDom );
+        }
+    }
 
-	/**
-	 * Copies a entire directory structure without scm files.
-	 * 
-	 * Note:
-	 * <ul>
-	 * <li>It will include empty directories.
-	 * <li>The <code>sourceDirectory</code> must exists.
-	 * </ul>
-	 * 
-	 * @param sourceDirectory
-	 * @param destinationDirectory
-	 * @throws IOException
-	 */
-	public static void copyDirectoryStructure(File sourceDirectory, File destinationDirectory) throws IOException {
-		if (!sourceDirectory.exists()) {
-			return;
-		}
+    /**
+     * Copy all files from application directory to the target eclipseEar directory.
+     * 
+     * @throws MojoExecutionException wenn an error occures during file copieing
+     */
+    private void copyApplicationFiles()
+        throws MojoExecutionException
+    {
+        try
+        {
+            File applicationDirectory =
+                new File( this.config.getEclipseProjectDirectory(), "src" + File.separator + "main" + File.separator
+                    + "application" );
+            File eclipseApplicationDirectory =
+                new File( this.config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" );
+            copyDirectoryStructure( applicationDirectory, eclipseApplicationDirectory );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "could not copy files the the eclipseEar directory", e );
+        }
+    }
 
-		File[] files = sourceDirectory.listFiles();
+    /**
+     * Copies a entire directory structure without scm files.
+     * 
+     * Note:
+     * <ul>
+     * <li>It will include empty directories.
+     * <li>The <code>sourceDirectory</code> must exists.
+     * </ul>
+     * 
+     * @param sourceDirectory
+     * @param destinationDirectory
+     * @throws IOException
+     */
+    public static void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
+        throws IOException
+    {
+        if ( !sourceDirectory.exists() )
+        {
+            return;
+        }
 
-		String sourcePath = sourceDirectory.getAbsolutePath();
+        File[] files = sourceDirectory.listFiles();
 
-		for (int i = 0; i < files.length; i++) {
-			File file = files[i];
+        String sourcePath = sourceDirectory.getAbsolutePath();
 
-			String dest = file.getAbsolutePath();
+        for ( int i = 0; i < files.length; i++ )
+        {
+            File file = files[i];
 
-			dest = dest.substring(sourcePath.length() + 1);
+            String dest = file.getAbsolutePath();
 
-			File destination = new File(destinationDirectory, dest);
+            dest = dest.substring( sourcePath.length() + 1 );
 
-			if (file.isFile()) {
-				destination = destination.getParentFile();
+            File destination = new File( destinationDirectory, dest );
 
-				FileUtils.copyFileToDirectory(file, destination);
-			} else if (file.isDirectory() && !file.getName().equals(".svn") && !file.getName().equals("CVS")) {
-				if (!destination.exists() && !destination.mkdirs()) {
-					throw new IOException("Could not create destination directory '" + destination.getAbsolutePath() + "'.");
-				}
+            if ( file.isFile() )
+            {
+                destination = destination.getParentFile();
 
-				copyDirectoryStructure(file, destination);
-			}
-		}
-	}
+                FileUtils.copyFileToDirectory( file, destination );
+            }
+            else if ( file.isDirectory() && !file.getName().equals( ".svn" ) && !file.getName().equals( "CVS" ) )
+            {
+                if ( !destination.exists() && !destination.mkdirs() )
+                {
+                    throw new IOException( "Could not create destination directory '" + destination.getAbsolutePath()
+                        + "'." );
+                }
 
-	/**
-	 * there is no existing application.xml file so create a new one.
-	 * 
-	 * @return the domtree representing the contents of application.xml
-	 */
-	private Xpp3Dom createNewApplicationXml() {
-		Xpp3Dom result = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_APPLICATION);
-		result.setAttribute(EclipseWtpApplicationXMLWriter.ID, "Application_ID");
-		result.setAttribute(EclipseWtpApplicationXMLWriter.VERSION, "1.4");
-		result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS, "http://java.sun.com/xml/ns/j2ee");
-		result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_XSI, "http://www.w3.org/2001/XMLSchema-instance");
-		result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_SCHEMA_LOCATION, "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd");
-		result.addChild(new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_DESCRIPTION));
-		Xpp3Dom name = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_DISPLAY_NAME);
-		name.setValue(this.config.getEclipseProjectName());
-		result.addChild(name);
-		return result;
-	}
+                copyDirectoryStructure( file, destination );
+            }
+        }
+    }
 
-	/**
-	 * there is no existing .modulemaps file so create a new one.
-	 * 
-	 * @return the domtree representing the contents of the .modulemaps file
-	 */
-	private Xpp3Dom createNewModulemaps() {
-		Xpp3Dom result = new Xpp3Dom(EclipseWtpApplicationXMLWriter.MODULEMAP_EARPROJECT_MAP);
-		result.setAttribute(EclipseWtpApplicationXMLWriter.XMI_VERSION, "2.0");
-		result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_XMI, "http://www.omg.org/XMI");
-		result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_APPLICATION, "application.xmi");
-		result.setAttribute(EclipseWtpApplicationXMLWriter.XMLNS_MODULEMAP, "modulemap.xmi");
-		result.setAttribute(EclipseWtpApplicationXMLWriter.XMI_ID, "EARProjectMap_" + System.identityHashCode(this));
-		return result;
-	}
+    /**
+     * there is no existing application.xml file so create a new one.
+     * 
+     * @return the domtree representing the contents of application.xml
+     */
+    private Xpp3Dom createNewApplicationXml()
+    {
+        Xpp3Dom result = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_APPLICATION );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.ID, "Application_ID" );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.VERSION, "1.4" );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS, "http://java.sun.com/xml/ns/j2ee" );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_XSI, "http://www.w3.org/2001/XMLSchema-instance" );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_SCHEMA_LOCATION,
+                             "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" );
+        result.addChild( new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_DESCRIPTION ) );
+        Xpp3Dom name = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_DISPLAY_NAME );
+        name.setValue( this.config.getEclipseProjectName() );
+        result.addChild( name );
+        return result;
+    }
 
-	/**
-	 * find an existing module entry in the application.xml file by looking up
-	 * the id in the modulemaps file and then using that to locate the entry in
-	 * the application.xml file.
-	 * 
-	 * @param applicationXmlDom
-	 *            application.xml dom tree
-	 * @param mapping
-	 *            .modulemaps dom tree
-	 * @return dom tree representing the module
-	 */
-	private Xpp3Dom findModuleInApplicationXml(Xpp3Dom applicationXmlDom, Xpp3Dom mapping) {
-		String id = getIdFromMapping(mapping);
-		Xpp3Dom[] children = applicationXmlDom.getChildren();
-		for (int index = 0; index < children.length; index++) {
-			String childId = children[index].getAttribute(EclipseWtpApplicationXMLWriter.ID);
-			if (childId != null && childId.equals(id)) {
-				return children[index];
-			}
-		}
-		return null;
-	}
+    /**
+     * there is no existing .modulemaps file so create a new one.
+     * 
+     * @return the domtree representing the contents of the .modulemaps file
+     */
+    private Xpp3Dom createNewModulemaps()
+    {
+        Xpp3Dom result = new Xpp3Dom( EclipseWtpApplicationXMLWriter.MODULEMAP_EARPROJECT_MAP );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.XMI_VERSION, "2.0" );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_XMI, "http://www.omg.org/XMI" );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_APPLICATION, "application.xmi" );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.XMLNS_MODULEMAP, "modulemap.xmi" );
+        result.setAttribute( EclipseWtpApplicationXMLWriter.XMI_ID, "EARProjectMap_" + System.identityHashCode( this ) );
+        return result;
+    }
 
-	/**
-	 * find an artifact in the modulemaps dom tree, if it is missing create a
-	 * new entry in the modulemaps dom tree.
-	 * 
-	 * @param dependency
-	 *            dependency to find
-	 * @param modulemapXmlDom
-	 *            dom-tree of modulemaps
-	 * @return dom-tree representing the artifact
-	 */
-	private Xpp3Dom findOrCreateArtifact(IdeDependency dependency, Xpp3Dom modulemapXmlDom) {
-		// first try to find it
-		Xpp3Dom[] children = modulemapXmlDom.getChildren();
-		for (int index = 0; index < children.length; index++) {
-			if (children[index].getAttribute(EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME).equals(dependency.getEclipseProjectName())) {
-				if ((dependency.getType().equals("ejb") || dependency.getType().equals("ejb3"))  && children[index].getName().equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS)
-						&& children[index].getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE).getAttribute(EclipseWtpApplicationXMLWriter.XMI_TYPE).equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_EJB_MODULE)) {
-					return children[index];
-				} else if (dependency.getType().equals("war") && children[index].getName().equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS)
-						&& children[index].getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE).getAttribute(EclipseWtpApplicationXMLWriter.XMI_TYPE).equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_WEB_MODULE)) {
-					return children[index];
-				} else if (dependency.getType().equals("jar") && children[index].getName().equals(EclipseWtpApplicationXMLWriter.MODULEMAPS_UTILITY_JARMAPPINGS)) {
-					return children[index];
-				} else {
-					modulemapXmlDom.removeChild(index);
-					break;
-				}
-			}
-		}
-		// ok, its missing (or it changed type). create a new one based on its
-		// type
-		long id = System.identityHashCode(dependency);
-		if (dependency.getType().equals("ejb") || dependency.getType().equals("ejb3")) {
-			Xpp3Dom mapping = new Xpp3Dom(EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS);
-			mapping.setAttribute(EclipseWtpApplicationXMLWriter.XMI_ID, "ModuleMapping_" + id);
-			mapping.setAttribute(EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
-			Xpp3Dom module = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
-			module.setAttribute(EclipseWtpApplicationXMLWriter.XMI_TYPE, EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_EJB_MODULE);
-			module.setAttribute(EclipseWtpApplicationXMLWriter.HREF, "META-INF/application.xml#EjbModule_" + id);
-			mapping.addChild(module);
-			modulemapXmlDom.addChild(mapping);
-			return mapping;
-		} else if (dependency.getType().equals("war")) {
-			Xpp3Dom mapping = new Xpp3Dom(EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS);
-			mapping.setAttribute(EclipseWtpApplicationXMLWriter.XMI_ID, "ModuleMapping_" + id);
-			mapping.setAttribute(EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
-			Xpp3Dom module = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
-			module.setAttribute(EclipseWtpApplicationXMLWriter.XMI_TYPE, EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_WEB_MODULE);
-			module.setAttribute(EclipseWtpApplicationXMLWriter.HREF, "META-INF/application.xml#WebModule_" + id);
-			mapping.addChild(module);
-			modulemapXmlDom.addChild(mapping);
-			return mapping;
-		} else {
-			Xpp3Dom utilityJARMapping = new Xpp3Dom(EclipseWtpApplicationXMLWriter.MODULEMAPS_UTILITY_JARMAPPINGS);
-			utilityJARMapping.setAttribute(EclipseWtpApplicationXMLWriter.XMI_ID, "UtilityJARMapping_" + id);
-			utilityJARMapping.setAttribute(EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
-			utilityJARMapping.setAttribute(EclipseWtpApplicationXMLWriter.URI, dependency.getEclipseProjectName() + ".jar");
-			modulemapXmlDom.addChild(utilityJARMapping);
-			return utilityJARMapping;
-		}
-	}
+    /**
+     * find an existing module entry in the application.xml file by looking up the id in the modulemaps file and then
+     * using that to locate the entry in the application.xml file.
+     * 
+     * @param applicationXmlDom application.xml dom tree
+     * @param mapping .modulemaps dom tree
+     * @return dom tree representing the module
+     */
+    private Xpp3Dom findModuleInApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom mapping )
+    {
+        String id = getIdFromMapping( mapping );
+        Xpp3Dom[] children = applicationXmlDom.getChildren();
+        for ( int index = 0; index < children.length; index++ )
+        {
+            String childId = children[index].getAttribute( EclipseWtpApplicationXMLWriter.ID );
+            if ( childId != null && childId.equals( id ) )
+            {
+                return children[index];
+            }
+        }
+        return null;
+    }
 
-	/**
-	 * get the id from the href of a modulemap.
-	 * 
-	 * @param mapping
-	 *            the dom-tree of modulemaps
-	 * @return module identifier
-	 */
-	private String getIdFromMapping(Xpp3Dom mapping) {
-		if (mapping.getChildCount() < 1) {
-			return "";
-		}
-		String href = mapping.getChild(0).getAttribute(EclipseWtpApplicationXMLWriter.HREF);
-		String id = href.substring(href.indexOf('#') + 1);
-		return id;
-	}
+    /**
+     * find an artifact in the modulemaps dom tree, if it is missing create a new entry in the modulemaps dom tree.
+     * 
+     * @param dependency dependency to find
+     * @param modulemapXmlDom dom-tree of modulemaps
+     * @return dom-tree representing the artifact
+     */
+    private Xpp3Dom findOrCreateArtifact( IdeDependency dependency, Xpp3Dom modulemapXmlDom )
+    {
+        // first try to find it
+        Xpp3Dom[] children = modulemapXmlDom.getChildren();
+        for ( int index = 0; index < children.length; index++ )
+        {
+            if ( children[index].getAttribute( EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME ).equals(
+                                                                                                                dependency.getEclipseProjectName() ) )
+            {
+                if ( ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) || dependency.getType().equals(
+                                                                                                                      "ejb3" ) )
+                    && children[index].getName().equals( EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS )
+                    && children[index].getChild( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE ).getAttribute(
+                                                                                                                       EclipseWtpApplicationXMLWriter.XMI_TYPE ).equals(
+                                                                                                                                                                         EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_EJB_MODULE ) )
+                {
+                    return children[index];
+                }
+                else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR )
+                    && children[index].getName().equals( EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS )
+                    && children[index].getChild( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE ).getAttribute(
+                                                                                                                       EclipseWtpApplicationXMLWriter.XMI_TYPE ).equals(
+                                                                                                                                                                         EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_WEB_MODULE ) )
+                {
+                    return children[index];
+                }
+                else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_JAR )
+                    && children[index].getName().equals( EclipseWtpApplicationXMLWriter.MODULEMAPS_UTILITY_JARMAPPINGS ) )
+                {
+                    return children[index];
+                }
+                else
+                {
+                    modulemapXmlDom.removeChild( index );
+                    break;
+                }
+            }
+        }
+        // ok, its missing (or it changed type). create a new one based on its
+        // type
+        long id = System.identityHashCode( dependency );
+        if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) || dependency.getType().equals( "ejb3" ) )
+        {
+            Xpp3Dom mapping = new Xpp3Dom( EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS );
+            mapping.setAttribute( EclipseWtpApplicationXMLWriter.XMI_ID, "ModuleMapping_" + id );
+            mapping.setAttribute( EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME,
+                                  dependency.getEclipseProjectName() );
+            Xpp3Dom module = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+            module.setAttribute( EclipseWtpApplicationXMLWriter.XMI_TYPE,
+                                 EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_EJB_MODULE );
+            module.setAttribute( EclipseWtpApplicationXMLWriter.HREF, "META-INF/application.xml#EjbModule_" + id );
+            mapping.addChild( module );
+            modulemapXmlDom.addChild( mapping );
+            return mapping;
+        }
+        else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) )
+        {
+            Xpp3Dom mapping = new Xpp3Dom( EclipseWtpApplicationXMLWriter.MODULEMAPS_MAPPINGS );
+            mapping.setAttribute( EclipseWtpApplicationXMLWriter.XMI_ID, "ModuleMapping_" + id );
+            mapping.setAttribute( EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME,
+                                  dependency.getEclipseProjectName() );
+            Xpp3Dom module = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+            module.setAttribute( EclipseWtpApplicationXMLWriter.XMI_TYPE,
+                                 EclipseWtpApplicationXMLWriter.MODULEMAPS_APPLICATION_WEB_MODULE );
+            module.setAttribute( EclipseWtpApplicationXMLWriter.HREF, "META-INF/application.xml#WebModule_" + id );
+            mapping.addChild( module );
+            modulemapXmlDom.addChild( mapping );
+            return mapping;
+        }
+        else
+        {
+            Xpp3Dom utilityJARMapping = new Xpp3Dom( EclipseWtpApplicationXMLWriter.MODULEMAPS_UTILITY_JARMAPPINGS );
+            utilityJARMapping.setAttribute( EclipseWtpApplicationXMLWriter.XMI_ID, "UtilityJARMapping_" + id );
+            utilityJARMapping.setAttribute( EclipseWtpApplicationXMLWriter.MODULEMAPS_PROJECT_NAME,
+                                            dependency.getEclipseProjectName() );
+            utilityJARMapping.setAttribute( EclipseWtpApplicationXMLWriter.URI, dependency.getEclipseProjectName()
+                + ".jar" );
+            modulemapXmlDom.addChild( utilityJARMapping );
+            return utilityJARMapping;
+        }
+    }
 
-	/**
-	 * mark the domtree entry as handled (all not handled ones will be deleted).
-	 * 
-	 * @param xpp3Dom
-	 *            dom element to mark handled
-	 */
-	private void handled(Xpp3Dom xpp3Dom) {
-		for (int index = 0; index < this.applicationXmlDomChildren.length; index++) {
-			if (this.applicationXmlDomChildren[index] == xpp3Dom) {
-				this.applicationXmlDomChildren[index] = null;
-			}
-		}
-		for (int index = 0; index < this.modulemapsXmlDomChildren.length; index++) {
-			if (this.modulemapsXmlDomChildren[index] == xpp3Dom) {
-				this.modulemapsXmlDomChildren[index] = null;
-			}
-		}
-	}
+    /**
+     * get the id from the href of a modulemap.
+     * 
+     * @param mapping the dom-tree of modulemaps
+     * @return module identifier
+     */
+    private String getIdFromMapping( Xpp3Dom mapping )
+    {
+        if ( mapping.getChildCount() < 1 )
+        {
+            return "";
+        }
+        String href = mapping.getChild( 0 ).getAttribute( EclipseWtpApplicationXMLWriter.HREF );
+        String id = href.substring( href.indexOf( '#' ) + 1 );
+        return id;
+    }
 
-	/**
-	 * read an xml file (application.xml or .modulemaps).
-	 * 
-	 * @param xmlFile
-	 *            an xmlfile
-	 * @return dom-tree representing the file contents
-	 */
-	private Xpp3Dom readXMLFile(File xmlFile) {
-		try {
-			FileReader reader1 = new FileReader(xmlFile);
-			Xpp3Dom applicationXmlDom = Xpp3DomBuilder.build(reader1);
-			return applicationXmlDom;
-		} catch (FileNotFoundException e) {
-			return null;
-		} catch (Exception e) {
-			this.log.error("cantreadfile" + xmlFile.getAbsolutePath());
-			// this will trigger creating a new file
-			return null;
-		}
-	}
+    /**
+     * mark the domtree entry as handled (all not handled ones will be deleted).
+     * 
+     * @param xpp3Dom dom element to mark handled
+     */
+    private void handled( Xpp3Dom xpp3Dom )
+    {
+        for ( int index = 0; index < this.applicationXmlDomChildren.length; index++ )
+        {
+            if ( this.applicationXmlDomChildren[index] == xpp3Dom )
+            {
+                this.applicationXmlDomChildren[index] = null;
+            }
+        }
+        for ( int index = 0; index < this.modulemapsXmlDomChildren.length; index++ )
+        {
+            if ( this.modulemapsXmlDomChildren[index] == xpp3Dom )
+            {
+                this.modulemapsXmlDomChildren[index] = null;
+            }
+        }
+    }
 
-	/**
-	 * delete all unused entries from the dom-trees.
-	 * 
-	 * @param applicationXmlDom
-	 *            dom-tree of application.xml
-	 * @param modulemapsXmlDom
-	 *            dom-tree of modulemaps
-	 */
-	private void removeUnusedEntries(Xpp3Dom applicationXmlDom, Xpp3Dom modulemapsXmlDom) {
-		for (int index = 0; index < this.modulemapsXmlDomChildren.length; index++) {
-			if (this.modulemapsXmlDomChildren[index] != null) {
-				Xpp3Dom[] newModulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
-				for (int newIndex = 0; newIndex < newModulemapsXmlDomChildren.length; newIndex++) {
-					if (newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index]) {
-						modulemapsXmlDom.removeChild(newIndex);
-						break;
-					}
-				}
-			}
-		}
-		for (int index = 0; index < this.applicationXmlDomChildren.length; index++) {
-			if (this.applicationXmlDomChildren[index] != null) {
-				Xpp3Dom[] newApplicationXmlDomChildren = applicationXmlDom.getChildren();
-				for (int newIndex = 0; newIndex < newApplicationXmlDomChildren.length; newIndex++) {
-					if (newApplicationXmlDomChildren[newIndex] == this.applicationXmlDomChildren[index]) {
-						applicationXmlDom.removeChild(newIndex);
-						break;
-					}
-				}
-			}
-		}
-	}
+    /**
+     * read an xml file (application.xml or .modulemaps).
+     * 
+     * @param xmlFile an xmlfile
+     * @return dom-tree representing the file contents
+     */
+    private Xpp3Dom readXMLFile( File xmlFile )
+    {
+        try
+        {
+            FileReader reader1 = new FileReader( xmlFile );
+            Xpp3Dom applicationXmlDom = Xpp3DomBuilder.build( reader1 );
+            return applicationXmlDom;
+        }
+        catch ( FileNotFoundException e )
+        {
+            return null;
+        }
+        catch ( Exception e )
+        {
+            this.log.error( "cantreadfile" + xmlFile.getAbsolutePath() );
+            // this will trigger creating a new file
+            return null;
+        }
+    }
 
-	/**
-	 * update the application.xml and the .modulemaps file for a specified
-	 * dependency.all WAR an EJB dependencies will go in both files all others
-	 * only in the modulemaps files. Webapplications contextroots are corrected
-	 * to the contextRoot specified in the pom.
-	 * 
-	 * @param applicationXmlDom
-	 *            dom-tree of application.xml
-	 * @param modulemapXmlDom
-	 *            dom-tree of modulemaps
-	 * @param dependency
-	 *            the eclipse dependency to handle
-	 */
-	private void updateApplicationXml(Xpp3Dom applicationXmlDom, Xpp3Dom modulemapXmlDom, IdeDependency dependency) {
-        if (dependency.isTestDependency() || dependency.isProvided() || dependency.isSystemScopedOutsideProject(this.config.getProject())) 
+    /**
+     * delete all unused entries from the dom-trees.
+     * 
+     * @param applicationXmlDom dom-tree of application.xml
+     * @param modulemapsXmlDom dom-tree of modulemaps
+     */
+    private void removeUnusedEntries( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapsXmlDom )
+    {
+        for ( int index = 0; index < this.modulemapsXmlDomChildren.length; index++ )
         {
+            if ( this.modulemapsXmlDomChildren[index] != null )
+            {
+                Xpp3Dom[] newModulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
+                for ( int newIndex = 0; newIndex < newModulemapsXmlDomChildren.length; newIndex++ )
+                {
+                    if ( newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index] )
+                    {
+                        modulemapsXmlDom.removeChild( newIndex );
+                        break;
+                    }
+                }
+            }
+        }
+        for ( int index = 0; index < this.applicationXmlDomChildren.length; index++ )
+        {
+            if ( this.applicationXmlDomChildren[index] != null )
+            {
+                Xpp3Dom[] newApplicationXmlDomChildren = applicationXmlDom.getChildren();
+                for ( int newIndex = 0; newIndex < newApplicationXmlDomChildren.length; newIndex++ )
+                {
+                    if ( newApplicationXmlDomChildren[newIndex] == this.applicationXmlDomChildren[index] )
+                    {
+                        applicationXmlDom.removeChild( newIndex );
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * update the application.xml and the .modulemaps file for a specified dependency.all WAR an EJB dependencies will
+     * go in both files all others only in the modulemaps files. Webapplications contextroots are corrected to the
+     * contextRoot specified in the pom.
+     * 
+     * @param applicationXmlDom dom-tree of application.xml
+     * @param modulemapXmlDom dom-tree of modulemaps
+     * @param dependency the eclipse dependency to handle
+     */
+    private void updateApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapXmlDom, IdeDependency dependency )
+    {
+        if ( dependency.isTestDependency() || dependency.isProvided()
+            || dependency.isSystemScopedOutsideProject( this.config.getProject() ) )
+        {
             return;
         }
-		Xpp3Dom mapping = findOrCreateArtifact(dependency, modulemapXmlDom);
-		handled(mapping);
-		if (dependency.getType().equals("ejb") || dependency.getType().equals("ejb3") ) {
-			Xpp3Dom module = findModuleInApplicationXml(applicationXmlDom, mapping);
-			if (module == null) {
-				module = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
-				module.setAttribute(EclipseWtpApplicationXMLWriter.ID, getIdFromMapping(mapping));
-				Xpp3Dom ejb = new Xpp3Dom("ejb");
-				ejb.setValue(dependency.getEclipseProjectName() + ".jar");
-				module.addChild(ejb);
-				applicationXmlDom.addChild(module);
-			} else {
-				handled(module);
-				module.getChild("ejb").setValue(dependency.getEclipseProjectName() + ".jar");
-			}
-		} else if (dependency.getType().equals("war")) {
-			String contextRootInPom = getContextRootFor(dependency.getEclipseProjectName());
-			Xpp3Dom module = findModuleInApplicationXml(applicationXmlDom, mapping);
-			if (module == null) {
-				module = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE);
-				module.setAttribute(EclipseWtpApplicationXMLWriter.ID, getIdFromMapping(mapping));
-				Xpp3Dom web = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB);
-				Xpp3Dom webUri = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB_URI);
-				webUri.setValue(dependency.getEclipseProjectName() + ".war");
-				Xpp3Dom contextRoot = new Xpp3Dom(EclipseWtpApplicationXMLWriter.APPLICATION_XML_CONTEXT_ROOT);
-				contextRoot.setValue(contextRootInPom);
-				web.addChild(webUri);
-				web.addChild(contextRoot);
-				module.addChild(web);
-				applicationXmlDom.addChild(module);
-			} else {
-				handled(module);
-				module.getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB).getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB_URI).setValue(dependency.getEclipseProjectName() + ".war");
-				module.getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB).getChild(EclipseWtpApplicationXMLWriter.APPLICATION_XML_CONTEXT_ROOT).setValue(contextRootInPom);
-			}
-		}
-	}
+        Xpp3Dom mapping = findOrCreateArtifact( dependency, modulemapXmlDom );
+        handled( mapping );
+        if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) || dependency.getType().equals( "ejb3" ) )
+        {
+            Xpp3Dom module = findModuleInApplicationXml( applicationXmlDom, mapping );
+            if ( module == null )
+            {
+                module = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+                module.setAttribute( EclipseWtpApplicationXMLWriter.ID, getIdFromMapping( mapping ) );
+                Xpp3Dom ejb = new Xpp3Dom( "ejb" );
+                ejb.setValue( dependency.getEclipseProjectName() + ".jar" );
+                module.addChild( ejb );
+                applicationXmlDom.addChild( module );
+            }
+            else
+            {
+                handled( module );
+                module.getChild( "ejb" ).setValue( dependency.getEclipseProjectName() + ".jar" );
+            }
+        }
+        else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) )
+        {
+            String contextRootInPom = getContextRootFor( dependency );
+            Xpp3Dom module = findModuleInApplicationXml( applicationXmlDom, mapping );
+            if ( module == null )
+            {
+                module = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_MODULE );
+                module.setAttribute( EclipseWtpApplicationXMLWriter.ID, getIdFromMapping( mapping ) );
+                Xpp3Dom web = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB );
+                Xpp3Dom webUri = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB_URI );
+                webUri.setValue( dependency.getEclipseProjectName() + ".war" );
+                Xpp3Dom contextRoot = new Xpp3Dom( EclipseWtpApplicationXMLWriter.APPLICATION_XML_CONTEXT_ROOT );
+                contextRoot.setValue( contextRootInPom );
+                web.addChild( webUri );
+                web.addChild( contextRoot );
+                module.addChild( web );
+                applicationXmlDom.addChild( module );
+            }
+            else
+            {
+                handled( module );
+                module.getChild( EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB ).getChild(
+                                                                                                EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB_URI ).setValue(
+                                                                                                                                                                   dependency.getEclipseProjectName()
+                                                                                                                                                                       + ".war" );
+                module.getChild( EclipseWtpApplicationXMLWriter.APPLICATION_XML_WEB ).getChild(
+                                                                                                EclipseWtpApplicationXMLWriter.APPLICATION_XML_CONTEXT_ROOT ).setValue(
+                                                                                                                                                                        contextRootInPom );
+            }
+        }
+    }
 
-	/**
-	 * Find the contextRoot specified in the pom and convert it into contectroot
-	 * for the application.xml.
-	 * 
-	 * @param artifactId
-	 *            the artifactid to search
-	 * @return string with the context root
-	 */
-	private String getContextRootFor(String artifactId) {
-		for (int index = 0; index < this.webModulesFromPoms.length; index++) {
-			if (this.webModulesFromPoms[index].getChild("artifactId").getValue().equals(artifactId)) {
-                return new File(this.webModulesFromPoms[index].getChild("contextRoot").getValue()).getName();
+    /**
+     * Find the contextRoot specified in the pom and convert it into contectroot for the application.xml.
+     * 
+     * @param dependency the artifact to search
+     * @return string with the context root
+     */
+    private String getContextRootFor( IdeDependency dependency )
+    {
+        String artifactId = dependency.getArtifactId();
+        String groupId = dependency.getGroupId();
+        for ( int index = 0; index < this.webModulesFromPoms.length; index++ )
+        {
+            Xpp3Dom webGroupId = this.webModulesFromPoms[index].getChild( "groupId" );
+            Xpp3Dom webArtifactId = this.webModulesFromPoms[index].getChild( "artifactId" );
+            Xpp3Dom webContextRoot = this.webModulesFromPoms[index].getChild( "contextRoot" );
+
+            if ( webContextRoot != null && webArtifactId != null && webArtifactId.getValue().equals( artifactId )
+                && webGroupId != null && webGroupId.getValue().equals( groupId ) )
+            {
+                return webContextRoot.getValue();
             }
-		}
-		return artifactId;
-	}
+        }
+        // no configuration found back to maven-ear-plugin default
+        return dependency.getArtifactId();
+    }
 
-	/**
-	 * write back a domtree to a xmlfile and use the pretty print for it so that
-	 * it is human readable.
-	 * 
-	 * @param xmlFile
-	 *            file to write to
-	 * @param xmlDomTree
-	 *            dom-tree to write
-	 * @throws MojoExecutionException
-	 *             if the file could not be written
-	 */
-	private void writePrettyXmlFile(File xmlFile, Xpp3Dom xmlDomTree) throws MojoExecutionException {
-		Xpp3Dom original = readXMLFile(xmlFile);
-		if (original != null && original.equals(xmlDomTree)) {
-			this.log.info("Rad6CleanMojo.unchanged" + xmlFile.getAbsolutePath());
-			return;
-		}
-		FileWriter w = null;
-		xmlFile.getParentFile().mkdirs();
-		try {
-			w = new FileWriter(xmlFile);
-		} catch (IOException ex) {
-			throw new MojoExecutionException("Rad6Plugin.erroropeningfile", ex); //$NON-NLS-1$
-		}
-		XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null);
-		Xpp3DomWriter.write(writer, xmlDomTree);
-		IOUtil.close(w);
-	}
+    /**
+     * write back a domtree to a xmlfile and use the pretty print for it so that it is human readable.
+     * 
+     * @param xmlFile file to write to
+     * @param xmlDomTree dom-tree to write
+     * @throws MojoExecutionException if the file could not be written
+     */
+    private void writePrettyXmlFile( File xmlFile, Xpp3Dom xmlDomTree )
+        throws MojoExecutionException
+    {
+        Xpp3Dom original = readXMLFile( xmlFile );
+        if ( original != null && original.equals( xmlDomTree ) )
+        {
+            this.log.info( "Rad6CleanMojo.unchanged" + xmlFile.getAbsolutePath() );
+            return;
+        }
+        FileWriter w = null;
+        xmlFile.getParentFile().mkdirs();
+        try
+        {
+            w = new FileWriter( xmlFile );
+        }
+        catch ( IOException ex )
+        {
+            throw new MojoExecutionException( "Rad6Plugin.erroropeningfile", ex ); //$NON-NLS-1$
+        }
+        XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );
+        Xpp3DomWriter.write( writer, xmlDomTree );
+        IOUtil.close( w );
+    }
 }
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpFacetsWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpFacetsWriter.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpFacetsWriter.java	(working copy)
@@ -19,6 +19,7 @@
 package org.apache.maven.plugin.eclipse.writers.wtp;
 
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
 import org.apache.maven.plugin.eclipse.Messages;
 import org.apache.maven.plugin.ide.IdeUtils;
 import org.apache.maven.plugin.ide.JeeUtils;
@@ -115,7 +116,7 @@
         writer.startElement( ELT_FIXED );
         writer.addAttribute( ATTR_FACET, FACET_JST_JAVA );
         writer.endElement(); // element fixed
-        if ( "war".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+        if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
         {
             writer.startElement( ELT_FIXED );
             writer.addAttribute( ATTR_FACET, FACET_JST_WEB );
@@ -125,7 +126,7 @@
             writer.addAttribute( ATTR_VERSION, JeeUtils.resolveServletVersion(config.getProject()) );
             writer.endElement(); // installed
         }
-        else if ( "ejb".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+        else if ( Constants.PROJECT_PACKAGING_EJB.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
         {
             writer.startElement( ELT_FIXED );
             writer.addAttribute( ATTR_FACET, FACET_JST_EJB );
@@ -135,7 +136,7 @@
             writer.addAttribute( ATTR_VERSION, JeeUtils.resolveEjbVersion(config.getProject()) );
             writer.endElement(); // installed
         }
-        else if ( "ear".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+        else if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
         {
             writer.startElement( ELT_FIXED );
             writer.addAttribute( ATTR_FACET, FACET_JST_EAR );
@@ -145,7 +146,7 @@
             writer.addAttribute( ATTR_VERSION, JeeUtils.resolveJeeVersion(config.getProject()) );
             writer.endElement(); // installed
         }
-        else if ( "jar".equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
+        else if ( Constants.PROJECT_PACKAGING_JAR.equalsIgnoreCase( packaging ) ) //$NON-NLS-1$
         {
             writer.startElement( ELT_FIXED );
             writer.addAttribute( ATTR_FACET, FACET_JST_UTILITY );
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/AbstractWtpResourceWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/AbstractWtpResourceWriter.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/AbstractWtpResourceWriter.java	(working copy)
@@ -18,9 +18,11 @@
  */
 package org.apache.maven.plugin.eclipse.writers.wtp;
 
+import java.io.File;
+
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
 import org.apache.maven.plugin.eclipse.Messages;
 import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter;
 import org.apache.maven.plugin.ide.IdeDependency;
@@ -28,21 +30,19 @@
 import org.apache.maven.plugin.ide.JeeUtils;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.xml.XMLWriter;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
 
-import java.io.File;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * Base class to hold common constants used by extending classes.
  * 
  * @author <a href="mailto:rahul.thakur.xdev@gmail.com">Rahul Thakur</a>
  * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
  */
-public abstract class AbstractWtpResourceWriter extends AbstractEclipseWriter
+public abstract class AbstractWtpResourceWriter
+    extends AbstractEclipseWriter
 {
 
+    private static final String ELT_DEPENDENCY_OBJECT = "dependent-object"; //$NON-NLS-1$
+
     private static final String ELT_DEPENDENCY_TYPE = "dependency-type"; //$NON-NLS-1$
 
     private static final String ATTR_HANDLE = "handle"; //$NON-NLS-1$
@@ -77,25 +77,22 @@
 
     protected static final String ELT_PROJECT_MODULES = "project-modules"; //$NON-NLS-1$
 
-    protected static final String ARTIFACT_MAVEN_WAR_PLUGIN = "maven-war-plugin"; //$NON-NLS-1$
-    
-    protected static final String ARTIFACT_MAVEN_EAR_PLUGIN = "maven-ear-plugin"; //$NON-NLS-1$
-
     /**
      * @param project
      * @param writer
      * @throws MojoExecutionException
      */
     protected void writeModuleTypeAccordingToPackaging( MavenProject project, XMLWriter writer,
-                                                        File buildOutputDirectory ) throws MojoExecutionException
+                                                        File buildOutputDirectory )
+        throws MojoExecutionException
     {
-        if ( "war".equals( config.getPackaging() ) ) //$NON-NLS-1$
+        if ( Constants.PROJECT_PACKAGING_WAR.equals( config.getPackaging() ) ) //$NON-NLS-1$
         {
             writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.web" ); //$NON-NLS-1$
 
             writer.startElement( ELT_VERSION );
 
-            writer.writeText( JeeUtils.resolveServletVersion(project) );
+            writer.writeText( JeeUtils.resolveServletVersion( project ) );
             writer.endElement();
 
             String contextRoot = config.getContextName();
@@ -105,29 +102,28 @@
             writer.addAttribute( ATTR_VALUE, contextRoot );
             writer.endElement();
         }
-        else if ( "ejb".equals( config.getPackaging() ) ) //$NON-NLS-1$
+        else if ( Constants.PROJECT_PACKAGING_EJB.equals( config.getPackaging() ) ) //$NON-NLS-1$
         {
             writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ejb" ); //$NON-NLS-1$
 
             writer.startElement( ELT_VERSION );
-            writer.writeText( JeeUtils.resolveEjbVersion(project) );
+            writer.writeText( JeeUtils.resolveEjbVersion( project ) );
 
             writer.endElement();
 
             writer.startElement( ELT_PROPERTY );
             writer.addAttribute( ATTR_NAME, "java-output-path" ); //$NON-NLS-1$
             writer.addAttribute( ATTR_VALUE, "/" + //$NON-NLS-1$
-                            IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory,
-                                                                false ) );
+                IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory, false ) );
             writer.endElement();
 
         }
-        else if ( "ear".equals( config.getPackaging() ) ) //$NON-NLS-1$
+        else if ( Constants.PROJECT_PACKAGING_EAR.equals( config.getPackaging() ) ) //$NON-NLS-1$
         {
             writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ear" ); //$NON-NLS-1$
 
             writer.startElement( ELT_VERSION );
-            writer.writeText( JeeUtils.resolveJeeVersion(project) );
+            writer.writeText( JeeUtils.resolveJeeVersion( project ) );
             writer.endElement();
         }
         else
@@ -138,8 +134,7 @@
             writer.startElement( ELT_PROPERTY );
             writer.addAttribute( ATTR_NAME, "java-output-path" ); //$NON-NLS-1$
             writer.addAttribute( ATTR_VALUE, "/" + //$NON-NLS-1$
-                            IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory,
-                                                                false ) );
+                IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory, false ) );
             writer.endElement();
         }
     }
@@ -153,10 +148,12 @@
      * @param basedir
      * @throws MojoExecutionException
      */
-    protected void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository, File basedir, String deployPath )
+    protected void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository,
+                                  File basedir, String deployPath )
         throws MojoExecutionException
     {
         String handle;
+        String dependentObject = null;
 
         if ( dep.isReferencedProject() )
         {
@@ -166,6 +163,14 @@
             // </dependent-module>
 
             handle = "module:/resource/" + dep.getEclipseProjectName() + "/" + dep.getEclipseProjectName(); //$NON-NLS-1$ //$NON-NLS-2$
+            if ( Constants.PROJECT_PACKAGING_EJB.equals( dep.getType() ) )
+            {
+                dependentObject = "EjbModule_";
+            }
+            else if ( Constants.PROJECT_PACKAGING_WAR.equals( dep.getType() ) )
+            {
+                dependentObject = "WebModule_";
+            }
         }
         else
         {
@@ -187,27 +192,32 @@
 
             if ( dep.isSystemScoped() )
             {
-                handle =
-                    "module:/classpath/lib/" //$NON-NLS-1$
-                                    + IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(),
-                                                                          repoFile, false );
+                handle = "module:/classpath/lib/" //$NON-NLS-1$
+                    + IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), repoFile, false );
             }
             else
             {
                 File localRepositoryFile = new File( localRepository.getBasedir() );
 
                 handle = "module:/classpath/var/M2_REPO/" //$NON-NLS-1$
-                                + IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, repoFile, false );
+                    + IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, repoFile, false );
             }
         }
 
         writer.startElement( ELT_DEPENDENT_MODULE );
 
-        writer.addAttribute( "archiveName",dep.getEclipseProjectName()+"."+dep.getType()); 
+        writer.addAttribute( "archiveName", dep.getEclipseProjectName() + "." + dep.getType() );
 
         writer.addAttribute( ATTR_DEPLOY_PATH, deployPath ); //$NON-NLS-1$
         writer.addAttribute( ATTR_HANDLE, handle );
 
+        if ( dependentObject != null && config.getWtpVersion() >= 2.0f )
+        {
+            writer.startElement( ELT_DEPENDENCY_OBJECT );
+            writer.writeText( dependentObject + System.identityHashCode( dep ) );
+            writer.endElement();
+        }
+
         writer.startElement( ELT_DEPENDENCY_TYPE );
         writer.writeText( "uses" ); //$NON-NLS-1$
         writer.endElement();
@@ -218,12 +228,12 @@
     protected void writeWarOrEarResources( XMLWriter writer, MavenProject project, ArtifactRepository localRepository )
         throws MojoExecutionException
     {
-        // use /WEB-INF/lib for war projects and / or the configured defaultLibBundleDir for ear projects  
-    	String deployDir = IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_EAR_PLUGIN,
-                "defaultLibBundleDir",
-                "/" );
-        
-        if (project.getPackaging().equals("war")) 
+        // use /WEB-INF/lib for war projects and / or the configured defaultLibBundleDir for ear projects
+        String deployDir =
+            IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN, "defaultLibBundleDir",
+                                       "/" );
+
+        if ( project.getPackaging().equals( Constants.PROJECT_PACKAGING_WAR ) )
         {
             deployDir = "/WEB-INF/lib";
         }
@@ -234,9 +244,9 @@
             String type = dep.getType();
 
             // NB war is needed for ear projects, we suppose nobody adds a war dependency to a war/jar project
-            // exclude test and provided and system dependencies outside the project 
-            if ( ( !dep.isTestDependency() && !dep.isProvided() && !dep.isSystemScopedOutsideProject(project))
-                            && ( "jar".equals( type ) || "ejb".equals( type ) || "ejb-client".equals( type ) || "war".equals( type ) ) ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            // exclude test and provided and system dependencies outside the project
+            if ( ( !dep.isTestDependency() && !dep.isProvided() && !dep.isSystemScopedOutsideProject( project ) )
+                && ( Constants.PROJECT_PACKAGING_JAR.equals( type ) || Constants.PROJECT_PACKAGING_EJB.equals( type ) || "ejb-client".equals( type ) || Constants.PROJECT_PACKAGING_WAR.equals( type ) ) ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
             {
                 addDependency( writer, dep, localRepository, config.getProject().getBasedir(), deployDir );
             }
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponent15Writer.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponent15Writer.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponent15Writer.java	(working copy)
@@ -41,11 +41,19 @@
 
     /**
      * Version number added to component configuration.
+     * 
      * @return <code>1.0</code>
      */
     protected String getProjectVersion()
     {
-        return "1.5.0"; //$NON-NLS-1$
+        if ( this.config.getWtpVersion() < 2.0f )
+        {
+            return "1.5.0"; //$NON-NLS-1$
+        }
+        else
+        {
+            return "2.0"; //$NON-NLS-1$
+        }
     }
 
     /**
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpmodulesWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpmodulesWriter.java	(revision 586302)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpmodulesWriter.java	(working copy)
@@ -19,9 +19,11 @@
 package org.apache.maven.plugin.eclipse.writers.wtp;
 
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.Constants;
 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
 import org.apache.maven.plugin.eclipse.Messages;
 import org.apache.maven.plugin.ide.IdeUtils;
+import org.apache.maven.plugin.ide.JeeUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 import org.codehaus.plexus.util.xml.XMLWriter;
@@ -75,9 +77,9 @@
         // deploy-path is "/" for utility and ejb projects, "/WEB-INF/classes" for webapps
 
         String target = "/"; //$NON-NLS-1$
-        if ( "war".equals( config.getPackaging() ) ) //$NON-NLS-1$
+        if ( Constants.PROJECT_PACKAGING_WAR.equals( config.getPackaging() ) ) //$NON-NLS-1$
         {
-            String warSourceDirectory = IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_WAR_PLUGIN,
+            String warSourceDirectory = IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
                                                                    "warSourceDirectory", //$NON-NLS-1$
                                                                    config.getProject().getBasedir()+"/src/main/webapp" ); //$NON-NLS-1$
 
@@ -91,7 +93,7 @@
 
             target = "/WEB-INF/classes"; //$NON-NLS-1$
         }
-        else if ( "ear".equals( config.getPackaging() ) ) //$NON-NLS-1$
+        else if ( Constants.PROJECT_PACKAGING_EAR.equals( config.getPackaging() ) ) //$NON-NLS-1$
         {
             writer.startElement( ELT_WB_RESOURCE );
             writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); //$NON-NLS-1$
Index: src/site/site.xml
===================================================================
--- src/site/site.xml	(revision 586302)
+++ src/site/site.xml	(working copy)
@@ -16,6 +16,7 @@
       <item name="Prevent Module References" href="examples/prevent-module-references.html"/>
       <item name="Attach Library Sources" href="examples/attach-library-sources.html"/>
       <item name="Provide Project Natures And Build Commands" href="examples/provide-project-natures-and-build-commands.html"/>
+      <item name="Multi-module projects with WTP" href="examples/multi-module-projects.html"/>
     </menu>
   </body>
 </project>

