Index: src/main/java/org/apache/maven/plugin/ide/IdeDependency.java
===================================================================
--- src/main/java/org/apache/maven/plugin/ide/IdeDependency.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/ide/IdeDependency.java	(working copy)
@@ -20,6 +20,8 @@
 
 import java.io.File;
 
+import org.apache.maven.project.MavenProject;
+
 /**
  * @author Fabrizio Giustina
  * @version $Id$
@@ -102,6 +104,7 @@
      */
     private int dependencyDepth;
 
+    private String eclipseProjectName;
     /**
      * 
      * @param groupId Group id
@@ -120,7 +123,7 @@
      */
     public IdeDependency( String groupId, String artifactId, String version, boolean referencedProject,
                           boolean testDependency, boolean systemScoped, boolean provided, boolean addedToClasspath,
-                          File file, String type, boolean osgiBundle, String osgiSymbolicName, int dependencyDepth )
+                          File file, String type, boolean osgiBundle, String osgiSymbolicName, int dependencyDepth ,String eclipseProjectName)
     {
         // group:artifact:version
         this.groupId = groupId;
@@ -142,6 +145,8 @@
         // file and type
         this.file = file;
         this.type = type;
+        
+        this.eclipseProjectName = eclipseProjectName;
     }
 
     /**
@@ -393,6 +398,10 @@
     public int compareTo( Object o )
     {
         IdeDependency dep = (IdeDependency) o;
+        if (isSystemScoped() && dep.isSystemScoped() && getFile().equals(dep.getFile())) 
+        {
+            return 0;
+        }
         int equals = this.getGroupId().compareTo( dep.getGroupId() );
         if ( equals != 0 )
         {
@@ -411,5 +420,43 @@
 
         return 0;
     }
+    
+    /**
+     * Is this dependency System scoped outside the eclipse project.
+     * @return Returns the systemScoped.
+     */
+    public boolean isSystemScopedOutsideProject( MavenProject project )
+    {
+        return this.systemScoped && !getFile().getAbsolutePath().startsWith(project.getBasedir().getAbsolutePath());
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean equals(Object obj) 
+    {
+        return compareTo(obj) == 0;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public int hashCode() {
+        if (isSystemScoped()) 
+        {
+            return getFile().hashCode();
+        } else 
+        {
+            return this.getGroupId().hashCode() ^ this.getArtifactId().hashCode() ^ this.getType().hashCode();
+        }
+    }
 
+    public String getEclipseProjectName() {
+        return eclipseProjectName;
+    }
+
+    public void setEclipseProjectName(String eclipseProjectName) {
+        this.eclipseProjectName = eclipseProjectName;
+    }
+
 }
Index: src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java	(working copy)
@@ -562,9 +562,12 @@
                                                                    .getScope() ), Artifact.SCOPE_PROVIDED.equals( art
                                                                    .getScope() ), art.getArtifactHandler()
                                                                    .isAddedToClasspath(), art.getFile(), art.getType(),
-                                                               isOsgiBundle, osgiSymbolicName, dependencyDepth );
+                                                               isOsgiBundle, osgiSymbolicName, dependencyDepth , getProjectNameForArifact(art));
 
-                        dependencies.add( dep );
+                        if ( !dependencies.contains(dep) ) 
+                        {
+                            dependencies.add( dep );
+                        }
                     }
 
                 }
@@ -579,6 +582,8 @@
         return ideDeps;
     }
 
+    abstract public String getProjectNameForArifact(Artifact art) ;
+
     /**
      * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with
      * the <code>resolved</code> property set to true.
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpComponentWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpComponentWriter.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpComponentWriter.java	(working copy)
@@ -122,7 +122,7 @@
         }
         writer.startElement( ELT_WB_MODULE );
 
-        writer.addAttribute( ATTR_DEPLOY_NAME, config.getProject().getArtifactId() );
+        writer.addAttribute( ATTR_DEPLOY_NAME, this.config.getEclipseProjectName() );
 
         // deploy-path is "/" for utility and ejb projects, "/WEB-INF/classes" for webapps
         String target = "/"; //$NON-NLS-1$
@@ -156,7 +156,14 @@
         {
             writer.startElement( ELT_WB_RESOURCE );
             writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); //$NON-NLS-1$
-            writer.addAttribute( ATTR_SOURCE_PATH, "/" ); //$NON-NLS-1$
+            if ( this.config.isWtpApplicationXml() ) 
+            {
+                writer.addAttribute( ATTR_SOURCE_PATH, "/target/eclipseEar" ); //$NON-NLS-1$ 
+            }
+            else
+            {
+                writer.addAttribute( ATTR_SOURCE_PATH, "/" ); //$NON-NLS-1$
+            }
             writer.endElement();
         }
 
@@ -191,7 +198,7 @@
     protected void writeContextRoot( XMLWriter writer )
     {
         writer.startElement( ELT_PROPERTY );
-        writer.addAttribute( ATTR_CONTEXT_ROOT, config.getProject().getArtifactId() );
+        writer.addAttribute( ATTR_CONTEXT_ROOT, this.config.getEclipseProjectName() );
         writer.endElement(); // property
     }
 
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java	(working copy)
@@ -20,9 +20,11 @@
 
 import java.io.File;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.eclipse.Messages;
 import org.apache.maven.plugin.ide.IdeDependency;
@@ -30,6 +32,7 @@
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.XMLWriter;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
  * Base class to hold common constants used by extending classes.
@@ -95,7 +98,7 @@
             writer.endElement();
 
             // use finalName as context root only if it has been explicitely set
-            String contextRoot = project.getArtifactId();
+            String contextRoot = this.config.getEclipseProjectName();
             String finalName = project.getBuild().getFinalName();
             if ( !finalName.equals( project.getArtifactId() + "-" + project.getVersion() ) ) //$NON-NLS-1$
             {
@@ -153,7 +156,7 @@
      * @param basedir
      * @throws MojoExecutionException
      */
-    protected void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository, File basedir )
+    protected void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository, File basedir, String deployPath )
         throws MojoExecutionException
     {
         String handle;
@@ -165,7 +168,7 @@
             // <dependency-type>uses</dependency-type>
             // </dependent-module>
 
-            handle = "module:/resource/" + dep.getArtifactId() + "/" + dep.getArtifactId(); //$NON-NLS-1$ //$NON-NLS-2$
+            handle = "module:/resource/" + dep.getEclipseProjectName() + "/" + dep.getEclipseProjectName(); //$NON-NLS-1$ //$NON-NLS-2$
         }
         else
         {
@@ -201,7 +204,9 @@
 
         writer.startElement( ELT_DEPENDENT_MODULE );
 
-        writer.addAttribute( ATTR_DEPLOY_PATH, "/WEB-INF/lib" ); //$NON-NLS-1$
+        writer.addAttribute( "archiveName",dep.getEclipseProjectName()+"."+dep.getType()); 
+
+        writer.addAttribute( ATTR_DEPLOY_PATH, deployPath ); //$NON-NLS-1$
         writer.addAttribute( ATTR_HANDLE, handle );
 
         writer.startElement( ELT_DEPENDENCY_TYPE );
@@ -214,7 +219,25 @@
     protected void writeWarOrEarResources( XMLWriter writer, MavenProject project, ArtifactRepository localRepository )
         throws MojoExecutionException
     {
-
+        String deployDir = "/";
+        /*build/plugins/plugin/
+         *  artifactId maven-ear-plugin
+         *  configuration/defaultLibBundleDir
+         */
+        List plugins = project.getBuild().getPlugins();
+        for (Iterator iterator = plugins.iterator(); iterator.hasNext();) {
+            Plugin plugin = (Plugin) iterator.next();
+            if ("maven-ear-plugin".equals(plugin.getArtifactId())) {
+                Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration();
+                if (config!=null && config.getChild("defaultLibBundleDir")!=null) {
+                    deployDir=deployDir+ config.getChild("defaultLibBundleDir").getValue();
+                }
+            }
+        }
+        
+        if (project.getPackaging().equals("war")) {
+            deployDir="/WEB-INF/lib";
+        }
         // dependencies
         for ( int j = 0; j < config.getDeps().length; j++ )
         {
@@ -223,10 +246,10 @@
 
             // NB war is needed for ear projects, we suppose nobody adds a war dependency to a war/jar project
             // exclude test and provided deps
-            if ( ( !dep.isTestDependency() && !dep.isProvided() )
+            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$
             {
-                addDependency( writer, dep, localRepository, config.getProject().getBasedir() );
+                addDependency( writer, dep, localRepository, config.getProject().getBasedir() ,deployDir);
             }
         }
     }
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpmodulesWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpmodulesWriter.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpmodulesWriter.java	(working copy)
@@ -64,7 +64,7 @@
         writer.addAttribute( ATTR_MODULE_ID, "moduleCoreId" ); //$NON-NLS-1$
 
         writer.startElement( ELT_WB_MODULE );
-        writer.addAttribute( ATTR_DEPLOY_NAME, config.getProject().getArtifactId() );
+        writer.addAttribute( ATTR_DEPLOY_NAME, this.config.getEclipseProjectName() );
 
         writer.startElement( ELT_MODULE_TYPE );
         writeModuleTypeAccordingToPackaging( config.getProject(), writer, config.getBuildOutputDirectory() );
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpComponent15Writer.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpComponent15Writer.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpComponent15Writer.java	(working copy)
@@ -55,7 +55,7 @@
     {
         writer.startElement( ELT_PROPERTY );
         writer.addAttribute( ATTR_NAME, ATTR_CONTEXT_ROOT );
-        writer.addAttribute( ATTR_VALUE, config.getProject().getArtifactId() );
+        writer.addAttribute( ATTR_VALUE, this.config.getEclipseProjectName() );
         writer.endElement(); // property
     }
 
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java	(working copy)
@@ -83,6 +83,13 @@
     private boolean pde;
 
     /**
+     * eclipse ear application xml.
+     */
+    private boolean wtpApplicationXml;
+    
+    private boolean addVersionToProjectName;
+    
+    /**
      * Project natures.
      */
     private List projectnatures;
@@ -280,6 +287,24 @@
     }
 
     /**
+     * Getter for <code>pde</code>.
+     * @return Returns the pde.
+     */
+    public boolean isWtpApplicationXml()
+    {
+        return this.wtpApplicationXml;
+    }
+
+    /**
+     * Setter for <code>pde</code>.
+     * @param pde The pde to set.
+     */
+    public void setWtpApplicationXml( boolean wtpApplicationXml )
+    {
+        this.wtpApplicationXml = wtpApplicationXml;
+    }
+
+    /**
      * Getter for <code>buildCommands</code>.
      * @return Returns the buildCommands.
      */
@@ -332,4 +357,12 @@
     {
         this.projectBaseDir = projectBaseDir;
     }
+
+    public boolean isAddVersionToProjectName() {
+        return addVersionToProjectName;
+    }
+
+    public void setAddVersionToProjectName(boolean addVersionToProjectName) {
+        this.addVersionToProjectName = addVersionToProjectName;
+    }
 }
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java	(working copy)
@@ -192,7 +192,7 @@
                 if ( dep.isReferencedProject() )
                 {
                     writer.startElement( "project" ); //$NON-NLS-1$
-                    writer.writeText( dep.getArtifactId() );
+                    writer.writeText( dep.getEclipseProjectName() );
                     writer.endElement();
                 }
             }
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseManifestWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseManifestWriter.java	(revision 0)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseManifestWriter.java	(revision 0)
@@ -0,0 +1,399 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.eclipse.writers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.apache.maven.archiver.ManifestConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Resource;
+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.IdeDependency;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.jar.ManifestException;
+
+/**
+ * Create or adapt the manifest files for the RAD6 runtime dependencys.
+ * attention these will not be used for the real ear these are just to get the
+ * runtime enviorment using the maven dependencies.
+ * 
+ * WARNING: The manifest resources added here will not have the benefit of the
+ * dependencies of the project, since that's not provided in the setup() apis,
+ * one of the locations from which this writer is used in the RadPlugin.
+ * 
+ * @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven </a>
+ */
+public class EclipseManifestWriter extends AbstractEclipseWriter {
+
+    private static final String MANIFEST_MF_FILENAME = "MANIFEST.MF";
+
+    private static final String META_INF_DIRECTORY = "META-INF";
+
+    private static final String GENERATED_RESOURCE_DIRNAME = "target" + File.separatorChar + "generated-resources" + File.separatorChar + "eclipse";
+
+    private static final String WEBAPP_RESOURCE_DIR = "src" + File.separatorChar + "main" + File.separatorChar + "webapp";
+
+    /**
+     * Search the project for the existing META-INF directory where the manifest
+     * should be located.
+     * 
+     * @return the apsolute path to the META-INF directory
+     */
+    public String getMetaInfBaseDirectory(MavenProject project) {
+        String metaInfBaseDirectory = null;
+
+        if (config.getProject().getPackaging().equals(Constants.PROJECT_PACKAGING_WAR)) {
+            metaInfBaseDirectory = config.getProject().getBasedir().getAbsolutePath() + File.separatorChar + WEBAPP_RESOURCE_DIR;
+
+            log.debug("Attempting to use: " + metaInfBaseDirectory + " for location of META-INF in war project.");
+
+            File metaInfDirectoryFile = new File(metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY);
+
+            if (metaInfDirectoryFile.exists() && !metaInfDirectoryFile.isDirectory()) {
+                metaInfBaseDirectory = null;
+            }
+        }
+
+        for (int index = this.config.getSourceDirs().length - 1; metaInfBaseDirectory == null && index >= 0; index--) {
+            
+            File manifestFile = new File(this.config.getEclipseProjectDirectory(), this.config.getSourceDirs()[index].getPath() + File.separatorChar + META_INF_DIRECTORY + File.separatorChar + MANIFEST_MF_FILENAME);
+
+            log.debug("Checking for existence of META-INF/MANIFEST.MF file: " + manifestFile);
+
+            if (manifestFile.exists()) {
+                metaInfBaseDirectory = manifestFile.getParentFile().getParent();
+            }
+        }
+
+        return metaInfBaseDirectory;
+    }
+
+    /**
+     * Write the manifest files use an existing one it it exists (it will be
+     * overwritten!! in a war use webapp/META-INF else use the generated rad6
+     * sourcefolder
+     * 
+     * @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
+     */
+    public void write() throws MojoExecutionException {
+        String metaInfBaseDirectory = getMetaInfBaseDirectory(config.getProject());
+
+        if (metaInfBaseDirectory == null) {
+            // TODO: if this really is an error, shouldn't we stop the build??
+            throw new MojoExecutionException(Messages.getString("EclipseCleanMojo.nofilefound", new Object[] { META_INF_DIRECTORY }));
+        }
+
+        
+
+        if (config.isAddVersionToProjectName()) {
+            MavenArchiver mavenArchiver = new MavenArchiver();
+            ManifestConfiguration configuration = new ManifestConfiguration(){
+                public boolean isAddClasspath() {
+                    return true;
+                }
+            };
+            
+
+            File manifestFile = new File(metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY + File.separatorChar + MANIFEST_MF_FILENAME);
+            manifestFile.getParentFile().mkdirs();
+           
+            try {
+                PrintWriter printwriter = new PrintWriter(manifestFile);
+                mavenArchiver.getManifest(config.getProject(), configuration).write(printwriter);
+                printwriter.close();
+            } catch (Exception e) {
+                log.error(Messages.getString("EclipsePlugin.cantwritetofile", new Object[] { metaInfBaseDirectory + File.separatorChar + MANIFEST_MF_FILENAME }));
+            }
+        }else{
+            Manifest manifest = createNewManifest();
+       
+
+        File manifestFile = new File(metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY + File.separatorChar + MANIFEST_MF_FILENAME);
+
+        System.out.println("MANIFEST LOCATION: " + manifestFile);
+
+        if (shouldNewManifestFileBeWritten(manifest, manifestFile)) {
+            System.out.println("Writing manifest...");
+
+            manifestFile.getParentFile().mkdirs();
+
+            try {
+                FileOutputStream stream = new FileOutputStream(manifestFile);
+
+                manifest.write(stream);
+
+                stream.close();
+
+            } catch (Exception e) {
+                log.error(Messages.getString("EclipsePlugin.cantwritetofile", new Object[] { metaInfBaseDirectory + File.separatorChar + MANIFEST_MF_FILENAME }));
+            }
+
+        }
+        }
+    }
+
+    /**
+     * make room for a Manifest file. use a generated resource for JARS and for
+     * WARS use the manifest in the webapp/META-INF directory.
+     * 
+     * @throws MojoExecutionException
+     */
+    public static void addManifestResource(Log log,EclipseWriterConfig config) throws MojoExecutionException {
+
+        EclipseManifestWriter manifestWriter = new EclipseManifestWriter();
+        manifestWriter.init(log, config);
+
+        String packaging = config.getProject().getPackaging();
+
+        String manifestDirectory = manifestWriter.getMetaInfBaseDirectory(config.getProject());
+
+        if (!Constants.PROJECT_PACKAGING_EAR.equals(packaging) && !Constants.PROJECT_PACKAGING_WAR.equals(packaging) 
+                && manifestDirectory == null) {
+
+            String generatedResourceDir = config.getProject().getBasedir().getAbsolutePath() + File.separatorChar + GENERATED_RESOURCE_DIRNAME;
+
+            manifestDirectory = generatedResourceDir + File.separatorChar + "META-INF";
+
+            try {
+                new File(manifestDirectory).mkdirs();
+                File manifestFile = new File(manifestDirectory + File.separatorChar + "MANIFEST.MF");
+                if (manifestFile.exists()) {
+                    manifestFile.delete();
+                }
+                manifestFile.createNewFile();
+            } catch (IOException e) {
+                log.error(
+                      Messages.getString("EclipsePlugin.cantwritetofile", new Object[] { manifestDirectory + File.separatorChar + "META-INF" + File.separatorChar
+                              + "MANIFEST.MF" }));
+            }
+
+            log.debug("Adding " + GENERATED_RESOURCE_DIRNAME + " to eclipse sources ");
+
+            EclipseSourceDir[] sourceDirs = config.getSourceDirs();
+            EclipseSourceDir[] newSourceDirs = new EclipseSourceDir[sourceDirs.length + 1];
+            System.arraycopy(sourceDirs, 0, newSourceDirs, 0, sourceDirs.length);
+            newSourceDirs[sourceDirs.length] = new EclipseSourceDir(GENERATED_RESOURCE_DIRNAME, null, true, false, null, null, false);
+            config.setSourceDirs(newSourceDirs);
+        }
+
+        if (Constants.PROJECT_PACKAGING_WAR.equals(packaging)) {
+            new File(config.getProject().getBasedir().getAbsolutePath() + File.separatorChar + "src" + File.separatorChar + "main" + File.separatorChar + "webapp"
+                    + File.separatorChar + "META-INF").mkdirs();
+        }
+
+        // special case must be done first because it can add stuff to the
+        // classpath that will be
+        // written by the superclass
+        manifestWriter.write();
+    }
+    
+
+    /**
+     * Add one dependency to the black separated classpath stringbuffer. When
+     * the project is available in the reactor (current build) then the project
+     * is used else the jar representing the artifact. System dependencies will 
+     * only be included if they are in this project. 
+     * 
+     * @param classpath
+     *            existing classpath to append
+     * @param dependency
+     *            dependency to append as jar or as project
+     */
+    private void addDependencyToClassPath(StringBuffer classpath, IdeDependency dependency) {
+        if (!dependency.isTestDependency() && !dependency.isProvided() && !dependency.isSystemScopedOutsideProject(this.config.getProject())) {
+            
+            // blank is the separator in manifest classpath's
+            if (classpath.length() != 0) {
+                classpath.append(' ');
+            }
+            // if the dependency is a workspace project add the project and not
+            // the jar
+            if (!dependency.isReferencedProject()) {
+                classpath.append(dependency.getFile().getName());
+            } else {
+                classpath.append(dependency.getEclipseProjectName() + ".jar");
+            }
+        }
+    }
+
+    /**
+     * Check if the two manifests are equal. Manifest.equal can not be used
+     * because of the special case the Classpath entr, witch must be comaired
+     * sorted so that a different oder in the classpath does not result in "not
+     * equal". This not not realy correct but in this case it is more important
+     * to reduce the number of version-controll files.
+     * 
+     * @param manifest
+     *            the new manifest
+     * @param existingManifest
+     *            to compaire the new one with
+     * @return are the manifests equal
+     */
+    private boolean areManifestsEqual(Manifest manifest, Manifest existingManifest) {
+        if (existingManifest == null) {
+            return false;
+        }
+
+        Set keys = new HashSet();
+        Attributes existingMap = existingManifest.getMainAttributes();
+        Attributes newMap = manifest.getMainAttributes();
+        keys.addAll(existingMap.keySet());
+        keys.addAll(newMap.keySet());
+        Iterator iterator = keys.iterator();
+        while (iterator.hasNext()) {
+            Attributes.Name key = (Attributes.Name) iterator.next();
+            String newValue = (String) newMap.get(key);
+            String existingValue = (String) existingMap.get(key);
+            // special case classpath... they are qual when there entries
+            // are equal
+            if (Attributes.Name.CLASS_PATH.equals(key)) {
+                newValue = orderClasspath(newValue);
+                existingValue = orderClasspath(existingValue);
+            }
+            if ((newValue == null || !newValue.equals(existingValue)) && (existingValue == null || !existingValue.equals(newValue))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Convert all dependencies in a blank seperated list of jars and projects
+     * representing the classpath.
+     * 
+     * @return the blank separeted classpath string
+     */
+    private String constructManifestClasspath() {
+        StringBuffer stringBuffer = new StringBuffer();
+        IdeDependency[] deps = config.getDeps();
+
+        for (int index = 0; index < deps.length; index++) {
+            addDependencyToClassPath(stringBuffer, deps[index]);
+        }
+
+        return stringBuffer.toString();
+    }
+
+    /**
+     * Create a manifest contaigning the required classpath.
+     * 
+     * @return the newly created manifest
+     */
+    private Manifest createNewManifest() {
+        Manifest manifest = new Manifest();
+        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+        manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, constructManifestClasspath());
+        return manifest;
+    }
+
+    /**
+     * Aphabeticaly sort the classpath. Do this by splitting it up, sort the
+     * entries and gleue them together again.
+     * 
+     * @param newValue
+     *            classpath to sort
+     * @return the sorted classpath
+     */
+    private String orderClasspath(String newValue) {
+        if (newValue == null) 
+        {
+            return null;
+        }
+        String[] entries = newValue.split(" ");
+        Arrays.sort(entries);
+        StringBuffer buffer = new StringBuffer(newValue.length());
+        for (int index = 0; index < entries.length; index++) {
+            buffer.append(entries[index]);
+            buffer.append(' ');
+        }
+        return buffer.toString();
+    }
+
+    /**
+     * Read and parse the existing manifest file.
+     * 
+     * @param manifestFile
+     *            file
+     * @return the read manifest
+     * @throws IOException
+     *             if the file could not be read
+     */
+    private Manifest readExistingManifest(File manifestFile) throws IOException {
+        if (!manifestFile.exists()) {
+            return null;
+        }
+
+        Manifest existingManifest = new Manifest();
+        FileInputStream inputStream = new FileInputStream(manifestFile);
+        existingManifest.read(inputStream);
+        inputStream.close();
+        return existingManifest;
+    }
+
+    /**
+     * Verify is the manifest sould be overwritten this sould take in account
+     * that the manifest should only be written if the contents of the classpath
+     * was changed not the order. The classpath sorting oder should be ignored.
+     * 
+     * @param manifest
+     *            the newly created classpath
+     * @param manifestFile
+     *            the file where the manifest
+     * @return if the new manifest file must be written
+     * @throws MojoExecutionException
+     */
+    private boolean shouldNewManifestFileBeWritten(Manifest manifest, File manifestFile) throws MojoExecutionException {
+        try {
+            Manifest existingManifest = readExistingManifest(manifestFile);
+            if (areManifestsEqual(manifest, existingManifest)) {
+                log.info(Messages.getString("EclipseCleanMojo.unchanged", manifestFile.getAbsolutePath()));
+                return false;
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException(Messages.getString("EclipseCleanMojo.nofilefound", manifestFile.getAbsolutePath()), e);
+        }
+        return true;
+    }
+}
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpApplicationXMLWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpApplicationXMLWriter.java	(revision 0)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpApplicationXMLWriter.java	(revision 0)
@@ -0,0 +1,516 @@
+package org.apache.maven.plugin.eclipse.writers;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.EclipseSourceDir;
+import org.apache.maven.plugin.eclipse.writers.AbstractWtpResourceWriter;
+import org.apache.maven.plugin.ide.IdeDependency;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+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.
+ * 
+ * @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven</a>
+ */
+public class EclipseWtpApplicationXMLWriter extends AbstractWtpResourceWriter {
+	private static final String APPLICATION_XML_APPLICATION = "application";
+
+	private static final String APPLICATION_XML_CONTEXT_ROOT = "context-root";
+
+	private static final String APPLICATION_XML_DESCRIPTION = "description";
+
+	private static final String APPLICATION_XML_DISPLAY_NAME = "display-name";
+
+	private static final String APPLICATION_XML_FILENAME = "application.xml";
+
+	private static final String APPLICATION_XML_MODULE = "module";
+
+	private static final String APPLICATION_XML_WEB = "web";
+
+	private static final String APPLICATION_XML_WEB_URI = "web-uri";
+
+	private static final String HREF = "href";
+
+	private static final String ID = "id";
+
+	private static final String MODULEMAP_EARPROJECT_MAP = "modulemap:EARProjectMap";
+
+	private static final String MODULEMAPS_APPLICATION_EJB_MODULE = "application:EjbModule";
+
+	private static final String MODULEMAPS_APPLICATION_WEB_MODULE = "application:WebModule";
+
+	private static final String MODULEMAPS_FILENAME = ".modulemaps";
+
+	private static final String MODULEMAPS_MAPPINGS = "mappings";
+
+	private static final String MODULEMAPS_PROJECT_NAME = "projectName";
+
+	private static final String MODULEMAPS_UTILITY_JARMAPPINGS = "utilityJARMappings";
+
+	private static final String URI = "uri";
+
+	private static final String VERSION = "version";
+
+	private static final String XMI_ID = "xmi:id";
+
+	private static final String XMI_TYPE = "xmi:type";
+
+	private static final String XMI_VERSION = "xmi:version";
+
+	private static final String XMLNS = "xmlns";
+
+	private static final String XMLNS_APPLICATION = "xmlns:application";
+
+	private static final String XMLNS_MODULEMAP = "xmlns:modulemap";
+
+	private static final String XMLNS_SCHEMA_LOCATION = "xmlns:schemaLocation";
+
+	private static final String XMLNS_XMI = "xmlns:xmi";
+
+	private static final String XMLNS_XSI = "xmlns:xsi";
+
+	private Xpp3Dom[] applicationXmlDomChildren;
+
+	private Xpp3Dom[] modulemapsXmlDomChildren;
+
+	private Xpp3Dom[] webModulesFromPoms;
+
+	/**
+	 * 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 = config.getProject().getPackaging();
+		if ("ear".equalsIgnoreCase(packaging)) {
+			File applicationXmlFile = new File(config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" + File.separator + "META-INF" + File.separator
+					+ 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();
+
+			Xpp3Dom applicationXmlDom = readXMLFile(applicationXmlFile);
+			if (applicationXmlDom == null) {
+				applicationXmlDom = createNewApplicationXml();
+			}
+			this.applicationXmlDomChildren = applicationXmlDom.getChildren(APPLICATION_XML_MODULE);
+
+			File modulemapsXmlFile = new File(config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar" + File.separator + "META-INF" + File.separator
+					+ MODULEMAPS_FILENAME);
+			Xpp3Dom modulemapsXmlDom = readXMLFile(modulemapsXmlFile);
+			if (modulemapsXmlDom == null) {
+				modulemapsXmlDom = createNewModulemaps();
+			}
+			this.modulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
+
+			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");
+
+			IdeDependency[] deps = config.getDeps();
+			for (int index = 0; index < deps.length; index++) {
+				updateApplicationXml(applicationXmlDom, modulemapsXmlDom, deps[index]);
+			}
+
+			removeUnusedEntries(applicationXmlDom, modulemapsXmlDom);
+
+			writePrettyXmlFile(applicationXmlFile, applicationXmlDom);
+			writePrettyXmlFile(modulemapsXmlFile, 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(config.getEclipseProjectDirectory(), "src" + File.separator + "main" + File.separator + "application");
+			File eclipseApplicationDirectory = new File(config.getEclipseProjectDirectory(), "target" + File.separator + "eclipseEar");
+			copyDirectoryStructure(applicationDirectory, eclipseApplicationDirectory);
+		} catch (IOException e) {
+			throw new MojoExecutionException("could not copy files the the eclipseEar directory", e);
+		}
+	}
+
+	/**
+	 * 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()) {
+			throw new IOException("Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ").");
+		}
+
+		File[] files = sourceDirectory.listFiles();
+
+		String sourcePath = sourceDirectory.getAbsolutePath();
+
+		for (int i = 0; i < files.length; i++) {
+			File file = files[i];
+
+			String dest = file.getAbsolutePath();
+
+			dest = dest.substring(sourcePath.length() + 1);
+
+			File destination = new File(destinationDirectory, dest);
+
+			if (file.isFile()) {
+				destination = destination.getParentFile();
+
+				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() + "'.");
+				}
+
+				copyDirectoryStructure(file, destination);
+			}
+		}
+	}
+
+	/**
+	 * 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(APPLICATION_XML_APPLICATION);
+		result.setAttribute(ID, "Application_ID");
+		result.setAttribute(VERSION, "1.4");
+		result.setAttribute(XMLNS, "http://java.sun.com/xml/ns/j2ee");
+		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_1_4.xsd");
+		result.addChild(new Xpp3Dom(APPLICATION_XML_DESCRIPTION));
+		Xpp3Dom name = new Xpp3Dom(APPLICATION_XML_DISPLAY_NAME);
+		name.setValue(this.config.getEclipseProjectName());
+		result.addChild(name);
+		return result;
+	}
+
+	/**
+	 * 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(MODULEMAP_EARPROJECT_MAP);
+		result.setAttribute(XMI_VERSION, "2.0");
+		result.setAttribute(XMLNS_XMI, "http://www.omg.org/XMI");
+		result.setAttribute(XMLNS_APPLICATION, "application.xmi");
+		result.setAttribute(XMLNS_MODULEMAP, "modulemap.xmi");
+		result.setAttribute(XMI_ID, "EARProjectMap_" + System.identityHashCode(this));
+		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(ID);
+			if (childId != null && childId.equals(id)) {
+				return children[index];
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * 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(MODULEMAPS_PROJECT_NAME).equals(dependency.getEclipseProjectName())) {
+				if ((dependency.getType().equals("ejb") || dependency.getType().equals("ejb3"))  && 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("war") && 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("jar") && children[index].getName().equals(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(MODULEMAPS_MAPPINGS);
+			mapping.setAttribute(XMI_ID, "ModuleMapping_" + id);
+			mapping.setAttribute(MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
+			Xpp3Dom module = new Xpp3Dom(APPLICATION_XML_MODULE);
+			module.setAttribute(XMI_TYPE, MODULEMAPS_APPLICATION_EJB_MODULE);
+			module.setAttribute(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(MODULEMAPS_MAPPINGS);
+			mapping.setAttribute(XMI_ID, "ModuleMapping_" + id);
+			mapping.setAttribute(MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
+			Xpp3Dom module = new Xpp3Dom(APPLICATION_XML_MODULE);
+			module.setAttribute(XMI_TYPE, MODULEMAPS_APPLICATION_WEB_MODULE);
+			module.setAttribute(HREF, "META-INF/application.xml#WebModule_" + id);
+			mapping.addChild(module);
+			modulemapXmlDom.addChild(mapping);
+			return mapping;
+		} else {
+			Xpp3Dom utilityJARMapping = new Xpp3Dom(MODULEMAPS_UTILITY_JARMAPPINGS);
+			utilityJARMapping.setAttribute(XMI_ID, "UtilityJARMapping_" + id);
+			utilityJARMapping.setAttribute(MODULEMAPS_PROJECT_NAME, dependency.getEclipseProjectName());
+			utilityJARMapping.setAttribute(URI, dependency.getEclipseProjectName() + ".jar");
+			modulemapXmlDom.addChild(utilityJARMapping);
+			return utilityJARMapping;
+		}
+	}
+
+	/**
+	 * 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(HREF);
+		String id = href.substring(href.indexOf('#') + 1);
+		return id;
+	}
+
+	/**
+	 * 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;
+			}
+		}
+	}
+
+	/**
+	 * 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) {
+			log.error("cantreadfile" + xmlFile.getAbsolutePath());
+			// this will trigger creating a new file
+			return 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;
+					}
+				}
+			}
+		}
+	}
+
+	/**
+	 * 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(APPLICATION_XML_MODULE);
+				module.setAttribute(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(APPLICATION_XML_MODULE);
+				module.setAttribute(ID, getIdFromMapping(mapping));
+				Xpp3Dom web = new Xpp3Dom(APPLICATION_XML_WEB);
+				Xpp3Dom webUri = new Xpp3Dom(APPLICATION_XML_WEB_URI);
+				webUri.setValue(dependency.getEclipseProjectName() + ".war");
+				Xpp3Dom contextRoot = new Xpp3Dom(APPLICATION_XML_CONTEXT_ROOT);
+				contextRoot.setValue(contextRootInPom);
+				web.addChild(webUri);
+				web.addChild(contextRoot);
+				module.addChild(web);
+				applicationXmlDom.addChild(module);
+			} else {
+				handled(module);
+				module.getChild(APPLICATION_XML_WEB).getChild(APPLICATION_XML_WEB_URI).setValue(dependency.getEclipseProjectName() + ".war");
+				module.getChild(APPLICATION_XML_WEB).getChild(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 < webModulesFromPoms.length; index++) {
+			if (webModulesFromPoms[index].getChild("artifactId").getValue().equals(artifactId))
+				return new File(webModulesFromPoms[index].getChild("contextRoot").getValue()).getName();
+		}
+		return artifactId;
+	}
+
+	/**
+	 * 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)) {
+			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/EclipseClasspathWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java	(working copy)
@@ -366,7 +366,7 @@
 
         if ( dep.isReferencedProject() && !config.isPde() )
         {
-            path = "/" + dep.getArtifactId(); //$NON-NLS-1$
+            path = "/" + dep.getEclipseProjectName(); //$NON-NLS-1$
             kind = ATTR_SRC;
         }
         else if ( dep.isReferencedProject() && config.isPde() )
@@ -391,7 +391,7 @@
                 if ( log.isDebugEnabled() )
                 {
                     log.debug( Messages.getString( "EclipsePlugin.artifactissystemscoped", //$NON-NLS-1$
-                                                   new Object[] { dep.getArtifactId(), path } ) );
+                                                   new Object[] { dep.getEclipseProjectName(), path } ) );
                 }
 
                 kind = ATTR_LIB;
Index: src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java	(revision 494407)
+++ src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseOSGiManifestWriter.java	(working copy)
@@ -244,7 +244,7 @@
             {
                 bundleClasspathSb.append( "," + NEWLINE );
 
-                log.debug( "Adding artifact to manifest: " + dep.getArtifactId() );
+                log.debug( "Adding artifact to manifest: " + dep.getEclipseProjectName() );
 
                 bundleClasspathSb.append( " " + dep.getFile().getName() );
             }
Index: src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
===================================================================
--- src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java	(revision 516039)
+++ src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java	(working copy)
@@ -30,14 +30,17 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.eclipse.writers.EclipseClasspathWriter;
+import org.apache.maven.plugin.eclipse.writers.EclipseManifestWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseOSGiManifestWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseProjectWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseSettingsWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig;
+import org.apache.maven.plugin.eclipse.writers.EclipseWtpApplicationXMLWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseWtpComponent15Writer;
 import org.apache.maven.plugin.eclipse.writers.EclipseWtpComponentWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseWtpFacetsWriter;
@@ -65,6 +68,7 @@
  * @version $Id$
  * @goal eclipse
  * @execute phase="generate-resources"
+ * @requiresDependencyResolution runtime
  */
 public class EclipsePlugin
     extends AbstractIdeSupportMojo
@@ -236,6 +240,27 @@
     private boolean pde;
 
     /**
+     * Must the manifest files be written for java projects so that that the jee classpath for wtp is correct.
+     * 
+     * @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;
+
+    /**
+     * Must the manifest files be written for java projects so that that the jee classpath for wtp is correct.
+     * 
+     * @parameter expression="${eclipse.addVersionToProjectName}" default-value="false"
+     */
+    private boolean addVersionToProjectName;
+    
+    /**
      * The relative path of the manifest file
      *
      * @parameter expression="${eclipse.manifest}" default-value="${basedir}/META-INF/MANIFEST.MF"
@@ -650,6 +675,12 @@
         EclipseWriterConfig config = createEclipseWriterConfig( deps );
 
         // NOTE: This could change the config!
+        if (wtpmanifest && isJavaProject())
+        {
+            EclipseManifestWriter.addManifestResource(getLog(), config);
+        }
+        
+        // NOTE: This could change the config!
         writeExtraConfiguration( config );
 
         if ( wtpVersionFloat == 0.7f )
@@ -678,6 +709,11 @@
             new EclipseClasspathWriter().init( getLog(), config ).write();
         }
 
+        if (wtpapplicationxml)
+        {
+            new EclipseWtpApplicationXMLWriter().init(getLog(), config).write();
+        }
+
         if ( pde )
         {
             this.getLog().info( "The Maven Eclipse plugin runs in 'pde'-mode." );
@@ -732,8 +768,11 @@
 
         // TODO: add mojo param 'addVersionToProjectName' and if set append
         // -version to the project name.
-        config.setEclipseProjectName( project.getArtifactId() );
+        config.setEclipseProjectName(project.getArtifactId()
+                + (addVersionToProjectName ? "-" + project.getVersion() : ""));
 
+        config.setAddVersionToProjectName(addVersionToProjectName);
+
         Set convertedBuildCommands = new LinkedHashSet();
 
         if ( buildcommands != null )
@@ -762,6 +801,7 @@
         config.setLocalRepository( localRepository );
         config.setManifestFile( manifest );
         config.setPde( pde );
+        config.setWtpApplicationXml(wtpapplicationxml);
         config.setProject( project );
         config.setProjectBaseDir( projectBaseDir );
         config.setProjectnatures( projectnatures );
@@ -987,5 +1027,10 @@
                                                    resource.isFiltering() ) );
         }
     }
-
+    
+    public String getProjectNameForArifact(Artifact art)
+    {
+        // TODO Auto-generated method stub
+        return addVersionToProjectName ? art.getArtifactId() + "-" + art.getVersion() : art.getArtifactId();
+    }
 }
Index: pom.xml
===================================================================
--- pom.xml	(revision 494407)
+++ pom.xml	(working copy)
@@ -9,7 +9,7 @@
   <artifactId>maven-eclipse-plugin</artifactId>
   <packaging>maven-plugin</packaging>
   <name>Maven Eclipse Plugin</name>
-  <version>2.3</version>
+  <version>2.3-CFC-2007-03-08</version>
   <prerequisites>
     <maven>2.0.1</maven>
   </prerequisites>
@@ -150,4 +150,23 @@
     <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugins/tags/maven-eclipse-plugin-2.3</developerConnection>
     <url>https://svn.apache.org/repos/asf/maven/plugins/tags/maven-eclipse-plugin-2.3</url>
   </scm>
-</project>
\ No newline at end of file
+       <url>http://cfc073/developer-sites/maven-eclipse-plugin/${project.version}</url>
+        <distributionManagement>
+                <site>
+                        <id>cfc073site</id>
+                        <name>cfc073site</name>
+                        <url>sftp://maven:maven@cfc073/opt/maven-proxy/developer-sites/maven-eclipse-plugin/${project.version}</url>
+                </site>
+                <repository>
+                        <id>inhouse</id>
+                        <name>inhouse</name>
+                        <url>sftp://maven:maven@cfc073/opt/maven-proxy/maven2_repositories/free</url>
+                </repository>
+                <snapshotRepository>
+                        <id>inhouse-snapshot</id>
+                        <name>inhouse-snapshot</name>
+                        <url>sftp://maven:maven@cfc073/opt/maven-proxy/maven2_repositories/free</url>
+                </snapshotRepository>
+        </distributionManagement>
+
+</project>

