[234834] Adding external modules to EAR does not update deployment descriptor
diff --git a/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/AddModulestoEARPropertiesPage.java b/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/AddModulestoEARPropertiesPage.java
index 1993c90..67fdc5c 100644
--- a/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/AddModulestoEARPropertiesPage.java
+++ b/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/AddModulestoEARPropertiesPage.java
@@ -294,7 +294,7 @@
 		String virtCompURIMapName;
 		for(int i=0; i<componentList.size(); i++) {
 			virtComp = (IVirtualComponent)componentList.get(i);
-			virtCompURIMapName = getVirtualComponentNameWithExtension(virtComp);
+			virtCompURIMapName = getVirtualComponentNameWithExtension(virtComp);	
 			uriMap.put(virtComp, virtCompURIMapName);
 		}
 		dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_TO_URI_MAP, uriMap);
@@ -1175,19 +1175,31 @@
 	private String getVirtualComponentNameWithExtension(IVirtualComponent virtComp) {
 		String virtCompURIMapName = this.getURIMappingName(virtComp);
 		
-		if(JavaEEProjectUtilities.isDynamicWebComponent(virtComp) &&
-			!virtCompURIMapName.endsWith(IJ2EEModuleConstants.WAR_EXT)) {
-			//web module URIs need to end in WAR
-			virtCompURIMapName += IJ2EEModuleConstants.WAR_EXT;
-		} else if(JavaEEProjectUtilities.isJCAComponent(virtComp) &&
-			!virtCompURIMapName.endsWith(IJ2EEModuleConstants.RAR_EXT)) {
-			//connector module URIs need to end in RAR
-			virtCompURIMapName += IJ2EEModuleConstants.RAR_EXT;
-		} else if(!virtCompURIMapName.endsWith(IJ2EEModuleConstants.JAR_EXT)) {
-			//all other modules (EJB, AppClient, Utility) need to end in JAR
-			virtCompURIMapName += IJ2EEModuleConstants.JAR_EXT;
+		boolean linkedToEAR = true;
+		try {
+			if(virtComp.isBinary()){
+				linkedToEAR = ((J2EEModuleVirtualArchiveComponent)virtComp).isLinkedToEAR();
+				((J2EEModuleVirtualArchiveComponent)virtComp).setLinkedToEAR(false);
+			}
+			if(JavaEEProjectUtilities.isDynamicWebComponent(virtComp)) {
+				if(!virtCompURIMapName.endsWith(IJ2EEModuleConstants.WAR_EXT)) {
+					//web module URIs need to end in WAR
+					virtCompURIMapName += IJ2EEModuleConstants.WAR_EXT;
+				}
+			} else if(JavaEEProjectUtilities.isJCAComponent(virtComp)) {
+				if(!virtCompURIMapName.endsWith(IJ2EEModuleConstants.RAR_EXT)) {
+					//connector module URIs need to end in RAR
+					virtCompURIMapName += IJ2EEModuleConstants.RAR_EXT;
+				}
+			} else if(!virtCompURIMapName.endsWith(IJ2EEModuleConstants.JAR_EXT)) {
+				//all other modules (EJB, AppClient, Utility) need to end in JAR
+				virtCompURIMapName += IJ2EEModuleConstants.JAR_EXT;
+			}
+		} finally {
+			if(virtComp.isBinary()){
+				((J2EEModuleVirtualArchiveComponent)virtComp).setLinkedToEAR(linkedToEAR);
+			}
 		}
-		
 		return virtCompURIMapName;
 	}
 }
diff --git a/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/JavaEEArchiveUtilities.java b/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/JavaEEArchiveUtilities.java
index bb9214d..026df67 100644
--- a/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/JavaEEArchiveUtilities.java
+++ b/plugins/org.eclipse.jst.j2ee/archiveops/org/eclipse/jst/j2ee/internal/archive/JavaEEArchiveUtilities.java
@@ -30,6 +30,7 @@
 import org.eclipse.jdt.core.util.IClassFileAttribute;
 import org.eclipse.jdt.core.util.IClassFileReader;
 import org.eclipse.jdt.core.util.IRuntimeVisibleAnnotationsAttribute;
+import org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualArchiveComponent;
 import org.eclipse.jst.j2ee.internal.J2EEConstants;
 import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
 import org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentLoadAdapter;
@@ -49,7 +50,6 @@
 import org.eclipse.jst.jee.archive.internal.ZipFileArchiveLoadAdapterImpl;
 import org.eclipse.jst.jee.util.internal.JavaEEQuickPeek;
 import org.eclipse.wst.common.componentcore.ComponentCore;
-import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
 
 public class JavaEEArchiveUtilities extends ArchiveFactoryImpl implements IArchiveFactory {
@@ -117,31 +117,33 @@
 
 	public IArchive openArchive(IVirtualComponent virtualComponent) throws ArchiveOpenFailureException {
 		if (virtualComponent.isBinary()) {
-			VirtualArchiveComponent archiveComponent = (VirtualArchiveComponent) virtualComponent;
+			J2EEModuleVirtualArchiveComponent archiveComponent = (J2EEModuleVirtualArchiveComponent) virtualComponent;
 			JavaEEBinaryComponentLoadAdapter loadAdapter = new JavaEEBinaryComponentLoadAdapter(archiveComponent);
 			ArchiveOptions archiveOptions = new ArchiveOptions();
 			archiveOptions.setOption(ArchiveOptions.LOAD_ADAPTER, loadAdapter);
 			archiveOptions.setOption(ArchiveOptions.ARCHIVE_PATH, loadAdapter.getArchivePath());
 			IArchive parentEARArchive = null;
 			try {
-				try {
-					IProject earProject = virtualComponent.getProject();
-					if(earProject != null && EarUtilities.isEARProject(earProject)){
-						IVirtualComponent earComponent = ComponentCore.createComponent(virtualComponent.getProject());
-						if(earComponent != null) {
-							parentEARArchive = openArchive(earComponent);
-							if(parentEARArchive != null) {
-								archiveOptions.setOption(ArchiveOptions.PARENT_ARCHIVE, parentEARArchive);
+				if(archiveComponent.isLinkedToEAR()){
+					try {
+						IProject earProject = virtualComponent.getProject();
+						if(earProject != null && EarUtilities.isEARProject(earProject)){
+							IVirtualComponent earComponent = ComponentCore.createComponent(virtualComponent.getProject());
+							if(earComponent != null) {
+								parentEARArchive = openArchive(earComponent);
+								if(parentEARArchive != null) {
+									archiveOptions.setOption(ArchiveOptions.PARENT_ARCHIVE, parentEARArchive);
+								}
 							}
 						}
+					} catch(ArchiveOpenFailureException e) {
+						org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e);
 					}
-				} catch(ArchiveOpenFailureException e) {
-					org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e);
 				}
 				return openArchive(archiveOptions);
 			} finally {
-				archiveOptions.removeOption(ArchiveOptions.PARENT_ARCHIVE);
 				if(parentEARArchive != null){
+					archiveOptions.removeOption(ArchiveOptions.PARENT_ARCHIVE);
 					closeArchive(parentEARArchive);
 				}
 			}
diff --git a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java
index bdffb6f..01c62aa 100644
--- a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java
+++ b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java
@@ -27,6 +27,7 @@
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.jem.util.logger.proxy.Logger;
+import org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualArchiveComponent;
 import org.eclipse.jst.j2ee.internal.J2EEConstants;
 import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
 import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater;
@@ -116,25 +117,36 @@
 					for (int i = 0; i < list.size(); i++) {
 						StructureEdit compse = null;
 						final IVirtualComponent wc = (IVirtualComponent) list.get(i);
-						WorkbenchComponent earwc = se.getComponent();
-						try {
-							compse = StructureEdit.getStructureEditForWrite(wc.getProject());
-							WorkbenchComponent refwc = compse.getComponent();
-							final ReferencedComponent ref = se.findReferencedComponent(earwc, refwc);
-							earModel.modify(new Runnable() {
-								public void run() {
-									final ICommonApplication application = (ICommonApplication)earModel.getModelObject();
-									if(application != null) {
-										ICommonModule mod = addModule(application, wc, (String) map.get(wc));
-										if (ref!=null)
-											ref.setDependentObject((EObject)mod);
+						boolean linkedToEAR = true;
+						try{
+							if(wc.isBinary()){
+								linkedToEAR = ((J2EEModuleVirtualArchiveComponent)wc).isLinkedToEAR();
+								((J2EEModuleVirtualArchiveComponent)wc).setLinkedToEAR(false);
+							}
+							WorkbenchComponent earwc = se.getComponent();
+							try {
+								compse = StructureEdit.getStructureEditForWrite(wc.getProject());
+								WorkbenchComponent refwc = compse.getComponent();
+								final ReferencedComponent ref = se.findReferencedComponent(earwc, refwc);
+								earModel.modify(new Runnable() {
+									public void run() {
+										final ICommonApplication application = (ICommonApplication)earModel.getModelObject();
+										if(application != null) {
+											ICommonModule mod = addModule(application, wc, (String) map.get(wc));
+											if (ref!=null)
+												ref.setDependentObject((EObject)mod);
+										}
 									}
+								}, null);
+							} finally {
+								if (compse != null) {
+									compse.saveIfNecessary(monitor);
+									compse.dispose();
 								}
-							}, null);
+							}
 						} finally {
-							if (compse != null) {
-								compse.saveIfNecessary(monitor);
-								compse.dispose();
+							if(wc.isBinary()){
+								((J2EEModuleVirtualArchiveComponent)wc).setLinkedToEAR(linkedToEAR);
 							}
 						}
 					}
diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualArchiveComponent.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualArchiveComponent.java
index 15925d5..1c31884 100644
--- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualArchiveComponent.java
+++ b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualArchiveComponent.java
@@ -24,6 +24,8 @@
 
 	protected static final IVirtualReference[] NO_REFERENCES = new VirtualReference[0];
 
+	private boolean linkedToEAR = true;
+	
 	protected String[] manifestClasspath;
 
 	public J2EEModuleVirtualArchiveComponent(IProject aComponentProject, String archiveLocation, IPath aRuntimePath) {
@@ -50,4 +52,13 @@
 		}
 		return manifestClasspath;
 	}
+
+	public void setLinkedToEAR(boolean linkedToEAR) {
+		this.linkedToEAR = linkedToEAR;
+	}
+
+	public boolean isLinkedToEAR() {
+		return linkedToEAR;
+	}
+	
 }