[215538]
diff --git a/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/ClasspathTableManager.java b/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/ClasspathTableManager.java
index 5e38cf2..f603a11 100644
--- a/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/ClasspathTableManager.java
+++ b/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/ClasspathTableManager.java
@@ -61,6 +61,9 @@
 	protected ClasspathModel model;
 	protected CheckboxTableViewer availableJARsViewer;
 	protected IValidateEditListener validateEditListener;
+	/**
+	 * @deprecated this field should be removed
+	 */
 	protected boolean isWLPEntry;
 	protected Group radioGroup;
 	
@@ -74,9 +77,7 @@
 	 * Constructor for ButtonBarManager.
 	 */
 	public ClasspathTableManager(IClasspathTableOwner owner, ClasspathModel model) {
-		super();
-		this.owner = owner;
-		this.model = model;
+		this(owner, model, null);
 	}
 	
 	public ClasspathTableManager(IClasspathTableOwner owner, ClasspathModel model, IValidateEditListener listener) {
@@ -445,7 +446,6 @@
 	public void refresh() {
 		if (!isWLPEntry() && !J2EEProjectUtilities.isStandaloneProject(model.getComponent().getProject())) {
 			availableJARsViewer.setInput(getClasspathSelection());
-			model.setWLPModel(false);
 			GridData data = new GridData(GridData.FILL_BOTH);
 			int numlines = Math.min(10, availableJARsViewer.getTable().getItemCount());
 			data.heightHint = availableJARsViewer.getTable().getItemHeight() * numlines;
@@ -454,7 +454,6 @@
 			updateButtonEnablements();
 		} else {
 			availableJARsViewer.setInput(model.getClassPathSelectionForWLPs());
-			model.setWLPModel(true);
 			GridData data = new GridData(GridData.FILL_BOTH);
 			int numlines = Math.min(10, availableJARsViewer.getTable().getItemCount());
 			data.heightHint = availableJARsViewer.getTable().getItemHeight() * numlines;
@@ -511,9 +510,13 @@
 	}
 
 	public boolean isWLPEntry() {
-		return isWLPEntry;
+		return model.isWLPModel();
 	}
 
+	/**
+	 * @deprecated do not use this method
+	 * @param isWLPEntry
+	 */
 	public void setWLPEntry(boolean isWLPEntry) {
 		this.isWLPEntry = isWLPEntry;
 	}
diff --git a/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/JARDependencyPropertiesPage.java b/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/JARDependencyPropertiesPage.java
index ef8ed27..39bd21c 100644
--- a/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/JARDependencyPropertiesPage.java
+++ b/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/JARDependencyPropertiesPage.java
@@ -27,7 +27,6 @@
 import java.util.Map;
 import java.util.jar.Manifest;
 
-import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResourceDelta;
@@ -49,13 +48,13 @@
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
 import org.eclipse.jface.viewers.ColumnWeightData;
 import org.eclipse.jface.viewers.TableLayout;
 import org.eclipse.jst.j2ee.application.internal.operations.ClassPathSelection;
 import org.eclipse.jst.j2ee.application.internal.operations.ClasspathElement;
 import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil;
+import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants;
 import org.eclipse.jst.j2ee.classpathdep.UpdateClasspathAttributeUtil;
 import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest;
 import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifestImpl;
@@ -87,6 +86,7 @@
 import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities;
 import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
 import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
 import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
 import org.eclipse.wst.common.frameworks.internal.ui.WTPUIPlugin;
@@ -131,7 +131,7 @@
 	 * Returns false if page should not be displayed for the project.
 	 */
 	protected void initialize() {
-		model = new ClasspathModel(null);
+		model = createClasspathModel();
 		model.setProject(project);
 		if (model.getComponent() != null) {
 			model.addListener(this);
@@ -140,6 +140,10 @@
 		}
 	}
 
+	protected ClasspathModel createClasspathModel(){
+		return new ClasspathModel(null, false);
+	}
+
 	public void dispose() {
 		isDisposed = true;
 		JavaCore.removeElementChangedListener(this);
@@ -153,42 +157,40 @@
 	private void updateModelManifest() {
 		if (JemProjectUtilities.isBinaryProject(project) || model.getAvailableEARComponents().length == 0)
 			return;
-		IContainer root = null;
-		IFile manifestFile = null;
-		if (project != null)
-			root = project;
-		else
-			root = JemProjectUtilities.getSourceFolderOrFirst(project, null);
-
-		if (root != null)
-			manifestFile = root.getFile(new Path(J2EEConstants.MANIFEST_URI));
-
-		if (manifestFile == null || !manifestFile.exists())
-			return;
-
-		InputStream in = null;
-		try {
-			in = manifestFile.getContents();
-			ArchiveManifest mf = new ArchiveManifestImpl(new Manifest(in));
-			model.primSetManifest(mf);
-		} catch (CoreException e) {
-			Logger.getLogger().logError(e);
-			model.primSetManifest(new ArchiveManifestImpl());
-		} catch (IOException iox) {
-			Logger.getLogger().logError(iox);
-			model.primSetManifest(new ArchiveManifestImpl());
-			caughtManifestException = iox;
-		} finally {
-			if (in != null) {
-				try {
-					in.close();
-				} catch (IOException weTried) {
-					// Ignore
+		
+		IVirtualComponent component = ComponentCore.createComponent(project);
+		if(component != null){
+			IVirtualFile vManifest = component.getRootFolder().getFile(new Path(J2EEConstants.MANIFEST_URI));
+			if(vManifest.exists()){
+				IFile iManifest = vManifest.getUnderlyingFile();
+				if(iManifest != null && iManifest.exists()){
+					InputStream in = null;
+					try {
+						in = iManifest.getContents();
+						ArchiveManifest mf = new ArchiveManifestImpl(new Manifest(in));
+						model.primSetManifest(mf);
+					} catch (CoreException e) {
+						Logger.getLogger().logError(e);
+						model.primSetManifest(new ArchiveManifestImpl());
+					} catch (IOException iox) {
+						Logger.getLogger().logError(iox);
+						model.primSetManifest(new ArchiveManifestImpl());
+						caughtManifestException = iox;
+					} finally {
+						if (in != null) {
+							try {
+								in.close();
+							} catch (IOException weTried) {
+								// Ignore
+							}
+						}
+					}
 				}
 			}
 		}
 	}
 
+
 	protected void initializeValidateEditListener() {
 		validateEditListener = new ValidateEditListener(null, model);
 		validateEditListener.setShell(propPage.getShell());
@@ -557,8 +559,7 @@
 		if (!isDirty)
 			return true;
 		WorkspaceModifyComposedOperation composed = new WorkspaceModifyComposedOperation(createManifestOperation());
-		
-		composed.addRunnable(createClasspathAttributeUpdateOperation(model.getClassPathSelection(), false));
+		createClasspathAttributeUpdateOperation(composed, model.getClassPathSelection(), false);
 		try {
 			new ProgressMonitorDialog(propPage.getShell()).run(true, true, composed);
 		} catch (InvocationTargetException ex) {
@@ -636,6 +637,10 @@
 	}
 
 
+	/**
+	 * @deprecated don't use this method it will be deleted
+	 * @return
+	 */
 	List getUnSelectedClassPathElementsForWebDependency() {
 		List unselectedForWLP = getUnSelectedClassPathSelectionForWLPs().getClasspathElements();
 		List unselected = new ArrayList();
@@ -731,11 +736,15 @@
 	}
 
 
+	/**
+	 * This should be moved to the {@link WebLibDependencyPropertiesPage} because it is only used there.
+	 * @return
+	 */
 	protected WorkspaceModifyComposedOperation createComponentDependencyOperations() {
 		WorkspaceModifyComposedOperation composedOp = null;
 		final ClassPathSelection selectedWLPs = getSelectedClassPathSelectionForWLPs();
 		List selected = selectedWLPs.getClasspathElements();
-		List unselected = getUnSelectedClassPathElementsForWebDependency();
+		List unselected = getUnSelectedClassPathSelectionForWLPs().getClasspathElements();
 
 		List targetComponentsHandles = new ArrayList();
 		for (int i = 0; i < selected.size(); i++) {
@@ -794,7 +803,7 @@
 		if (composedOp == null) {
 			composedOp = new WorkspaceModifyComposedOperation();
 		}
-		composedOp.addRunnable(createClasspathAttributeUpdateOperation(selectedWLPs, true));
+		createClasspathAttributeUpdateOperation(composedOp, model.getClassPathSelectionForWLPs(), true);
 		
 		return composedOp;
 	}
@@ -866,20 +875,44 @@
 		return new UpdateManifestOperation(project.getName(), model.getClassPathSelection().toString(), true);
 	}
 	
-	protected IRunnableWithProgress createClasspathAttributeUpdateOperation(final ClassPathSelection selection, final boolean isWebApp) {
-		final Map entriesToRuntimePath = new HashMap();
-		final List selectedElements = selection.getSelectedClasspathElements();
-		for (int i = 0; i < selectedElements.size(); i++) {
-			final ClasspathElement element = (ClasspathElement) selectedElements.get(i);
-			if (element.isClasspathEntry() && element.isSelected()) {
+	protected void createClasspathAttributeUpdateOperation(final WorkspaceModifyComposedOperation composedOp, final ClassPathSelection selection, final boolean isWebApp) {
+		final Map selectedEntriesToRuntimePath = new HashMap();
+		final Map unselectedEntriesToRuntimePath = new HashMap();
+		final List elements = selection.getClasspathElements();
+		for (int i = 0; i < elements.size(); i++) {
+			final ClasspathElement element = (ClasspathElement) elements.get(i);
+			if (element.isClasspathEntry()) {
 				final IClasspathEntry entry = element.getClasspathEntry();
 				final IClasspathAttribute attrib = ClasspathDependencyUtil.checkForComponentDependencyAttribute(entry);
+				boolean hasDepAttrib = false;
+				if (attrib != null && attrib.getName().equals(IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY)) {
+					hasDepAttrib = true;
+				}
 				final IPath runtimePath = ClasspathDependencyUtil.getRuntimePath(attrib, isWebApp);
-				entriesToRuntimePath.put(entry, runtimePath);
+				if (element.isSelected()) {
+					// only add if we don't already have the attribute
+					if (!hasDepAttrib) {
+						selectedEntriesToRuntimePath.put(entry, runtimePath);
+					}
+				} else {
+					// only add if we already have the attribute
+					if (hasDepAttrib) {
+						unselectedEntriesToRuntimePath.put(entry, runtimePath);
+					}
+				}
 			}
 		}
-		final IDataModelOperation op = UpdateClasspathAttributeUtil.createUpdateDependencyAttributesOperation(project.getName(), entriesToRuntimePath); 
-		return WTPUIPlugin.getRunnableWithProgress(op);
+		
+		// if there are any attributes to add, create an operation to add all necessary attributes 
+		if (!selectedEntriesToRuntimePath.isEmpty()) {
+			IDataModelOperation op = UpdateClasspathAttributeUtil.createAddDependencyAttributesOperation(project.getName(), selectedEntriesToRuntimePath); 
+			composedOp.addRunnable(WTPUIPlugin.getRunnableWithProgress(op));
+		}
+		// if there are any attributes to remove, create an operation to remove all necessary attributes
+		if (!unselectedEntriesToRuntimePath.isEmpty()) {
+			IDataModelOperation op = UpdateClasspathAttributeUtil.createRemoveDependencyAttributesOperation(project.getName(), unselectedEntriesToRuntimePath); 
+			composedOp.addRunnable(WTPUIPlugin.getRunnableWithProgress(op));
+		}
 	}
 
 	protected boolean isReadOnly() {
diff --git a/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/WebLibDependencyPropertiesPage.java b/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/WebLibDependencyPropertiesPage.java
index 6f1f97f..acf7e3c 100644
--- a/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/WebLibDependencyPropertiesPage.java
+++ b/plugins/org.eclipse.jst.j2ee.ui/j2ee_ui/org/eclipse/jst/j2ee/internal/WebLibDependencyPropertiesPage.java
@@ -23,6 +23,7 @@
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
 import org.eclipse.jst.j2ee.application.internal.operations.ClasspathElement;
+import org.eclipse.jst.j2ee.internal.common.ClasspathModel;
 import org.eclipse.jst.j2ee.internal.common.ClasspathModelListener;
 import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
 import org.eclipse.swt.SWT;
@@ -45,6 +46,10 @@
 		super(project, page);
 	}
 
+	protected ClasspathModel createClasspathModel() {
+		return new ClasspathModel(null, true);
+	}
+	
 	public Composite createContents(Composite parent) {
 		initialize();
 		Composite composite = createBasicComposite(parent);
@@ -55,7 +60,6 @@
 			// createProjectLabelsGroup(composite);
 			createListGroup(composite);
 			handleWLPSupport();
-			model.setWLPModel(true);
 			setEnablement();
 		}
 	    Dialog.applyDialogFont(parent);
@@ -127,7 +131,6 @@
 	}
 
 	private void handleWLPSupport() {
-		tableManager.setWLPEntry(true);
 		availableDependentJars.setText(ManifestUIResourceHandler.WEB_LIB_LIST_DESCRIPTION);
 		tableManager.refresh();
 	}
diff --git a/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/UpdateClasspathAttributeUtil.java b/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/UpdateClasspathAttributeUtil.java
index d295928..c3bb92c 100644
--- a/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/UpdateClasspathAttributeUtil.java
+++ b/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/UpdateClasspathAttributeUtil.java
@@ -107,6 +107,28 @@
 	}
 	
 	/**
+	 * Creates the IDataModelOperation that will update the classpath for the specified Java project so that
+	 * the WTP component dependency attribute will be added to the specified list of classpath entries. 
+	 * @param projectName Name of the target Java project.
+	 * @param entryToRuntimePath Map from IClasspathEntry to runtime path for all entries that should have the attribute added.
+	 * @return The operation.
+	 */
+	public static IDataModelOperation createAddDependencyAttributesOperation(final String projectName, final Map entryToRuntimePath) {
+		return createOperation(projectName, entryToRuntimePath, UpdateClasspathAttributesDataModelProperties.ENTRIES_TO_ADD_ATTRIBUTE);
+	}
+	
+	/**
+	 * Creates the IDataModelOperation that will update the classpath for the specified Java project so that
+	 * the WTP component dependency attribute will be removed from the specified list of classpath entries. 
+	 * @param projectName Name of the target Java project.
+	 * @param entryToRuntimePath Map from IClasspathEntry to runtime path for all entries that should have the attribute removed.
+	 * @return The operation.
+	 */
+	public static IDataModelOperation createRemoveDependencyAttributesOperation(final String projectName, final Map entryToRuntimePath) {
+		return createOperation(projectName, entryToRuntimePath, UpdateClasspathAttributesDataModelProperties.ENTRIES_TO_REMOVE_ATTRIBUTE);
+	}
+	
+	/**
 	 * Adds the WTP component dependency attribute to the specified classpath entry using the default runtime path for the project. Does NOT check that the
 	 * specified entry is a valid entry for the dependency attribute.
 	 * 
diff --git a/plugins/org.eclipse.jst.j2ee/common/org/eclipse/jst/j2ee/internal/common/ClasspathModel.java b/plugins/org.eclipse.jst.j2ee/common/org/eclipse/jst/j2ee/internal/common/ClasspathModel.java
index 71c2b22..64d54ba 100644
--- a/plugins/org.eclipse.jst.j2ee/common/org/eclipse/jst/j2ee/internal/common/ClasspathModel.java
+++ b/plugins/org.eclipse.jst.j2ee/common/org/eclipse/jst/j2ee/internal/common/ClasspathModel.java
@@ -31,15 +31,11 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.emf.common.util.URI;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
 import org.eclipse.jem.util.logger.proxy.Logger;
 import org.eclipse.jst.j2ee.application.internal.operations.ClassPathSelection;
 import org.eclipse.jst.j2ee.application.internal.operations.ClasspathElement;
+import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil;
 import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive;
 import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.DeploymentDescriptorLoadException;
 import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.ManifestException;
@@ -49,7 +45,6 @@
 import org.eclipse.jst.j2ee.componentcore.util.EARArtifactEdit;
 import org.eclipse.jst.j2ee.internal.J2EEConstants;
 import org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities;
-import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater;
 import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
 import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
 import org.eclipse.jst.j2ee.model.IModelProvider;
@@ -58,8 +53,9 @@
 import org.eclipse.jst.jee.archive.IArchive;
 import org.eclipse.wst.common.componentcore.ComponentCore;
 import org.eclipse.wst.common.componentcore.UnresolveableURIException;
+import org.eclipse.wst.common.componentcore.internal.ModuleStructuralModel;
+import org.eclipse.wst.common.componentcore.internal.StructureEdit;
 import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil;
-import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent;
 import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
 import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
@@ -98,8 +94,13 @@
 
 
 	public ClasspathModel(ArchiveManifest initialManifest) {
+		this(initialManifest, false);
+	}
+	
+	public ClasspathModel(ArchiveManifest initialManifest, boolean isWLPModel) {
 		super();
 		manifest = initialManifest;
+		this.isWLPModel = isWLPModel;
 	}
 
 	public IProject getProject() {
@@ -466,14 +467,21 @@
 
 	protected void initNonResourceFiles() {
 		// Might be opened from a JAR
-		if (getComponent() == null)
+		if (getComponent() == null){
 			return;
-		nonResourceFiles = new ArrayList(3);
-		nonResourceFiles.add(getComponent().getProject().getFile(ProjectUtilities.DOT_PROJECT));
-		nonResourceFiles.add(getComponent().getProject().getFile(ProjectUtilities.DOT_CLASSPATH));
-		IFile mf = J2EEProjectUtilities.getManifestFile(getComponent().getProject());
-		if (mf != null)
-			nonResourceFiles.add(mf);
+		} 
+		nonResourceFiles = new ArrayList(1);
+		if(isWLPModel){
+			IFile dotProject = getComponent().getProject().getFile(ProjectUtilities.DOT_PROJECT);
+			if(dotProject != null){
+				nonResourceFiles.add(dotProject);
+			}
+		} else {
+			IFile mf = J2EEProjectUtilities.getManifestFile(getComponent().getProject());
+			if (mf != null){
+				nonResourceFiles.add(mf);
+			}
+		}
 	}
 
 
@@ -512,7 +520,26 @@
 	 * @see com.ibm.etools.emf.workbench.ResourceStateInputProvider#getResources()
 	 */
 	public List getResources() {
-		return Collections.EMPTY_LIST;
+		if(isWLPModel){
+			StructureEdit sEdit = null;
+			try {
+				sEdit = StructureEdit.getStructureEditForWrite(project);
+				ModuleStructuralModel structuralModel = sEdit.getModuleStructuralModel();
+				List resources = new ArrayList();
+				resources.addAll(structuralModel.getResources());
+				return resources;
+			} catch(Exception e){
+				e.printStackTrace();
+				return Collections.EMPTY_LIST;	
+			}
+			finally {
+				if (sEdit !=null){
+					sEdit.dispose();
+				}
+			}
+		} else {
+			return Collections.EMPTY_LIST;
+		}
 	}
 
 	public boolean selectDependencyIfNecessary(IProject referencedProject) {
@@ -637,199 +664,131 @@
 		return classPathWLPSelection;
 	}
 
+	//copied from WebArtifactEdit
+	private static IPath WEBLIB =  new Path(J2EEConstants.WEB_INF_LIB).makeAbsolute();
+	private static IVirtualReference[] getLibModules(IProject project) {
+		List result = new ArrayList();
+		IVirtualComponent comp = ComponentCore.createComponent(project);
+		IVirtualReference[] refComponents = null;
+		if (!comp.isBinary())
+			refComponents = ((J2EEModuleVirtualComponent)comp).getNonManifestReferences();
+		else
+			refComponents = comp.getReferences();
+		// Check the deployed path to make sure it has a lib parent folder and matchs the web.xml
+		// base path
+		for (int i = 0; i < refComponents.length; i++) {
+			if (refComponents[i].getRuntimePath().equals(WEBLIB))
+				result.add(refComponents[i]);
+		}
+
+		return (IVirtualReference[]) result.toArray(new IVirtualReference[result.size()]);
+	}
+	
 	private void initializeSelectionForWLPs() {
 		classPathWLPSelection = new ClassPathSelection();
-		try {
-			IClasspathContainer container = J2EEComponentClasspathUpdater.getInstance().getWebAppLibrariesContainer(component.getProject(), true);
-			IClasspathEntry[] containerEntries = null != container ? container.getClasspathEntries() : null;
-			IPath libPath = new Path("/WEB-INF/lib"); //$NON-NLS-1$
-
-			HashSet hs = new HashSet();
-			hs.addAll(J2EEProjectUtilities.getAllJavaNonFlexProjects());
-			IProject[] utilityProjects = J2EEProjectUtilities.getAllProjectsInWorkspaceOfType(J2EEProjectUtilities.UTILITY);
-			hs.addAll(Arrays.asList(utilityProjects));
-			
-			IProject[] ejbProjects = J2EEProjectUtilities.getAllProjectsInWorkspaceOfType(J2EEProjectUtilities.EJB);
-			hs.addAll(Arrays.asList(ejbProjects));
-			
-			Map pathToComp = new HashMap();
-			
-			for (Iterator it = hs.iterator(); it.hasNext();) {
-				Object item = it.next();
-				IProject utilProject = null;
-				IVirtualComponent comp = null;				
-				if (item instanceof IProject) {
-					utilProject = (IProject) item;
-					comp = ComponentCore.createComponent(utilProject);
-					if (utilProject.getName().startsWith(".")) { //$NON-NLS-1$
-						continue;
+		classPathWLPSelection.setFilterLevel(ClassPathSelection.FILTER_NONE);
+		//this is the set of all projects that are already mapped as web library projects
+		HashSet existingWebLibProjects = new HashSet();
+		List otherExistingWebLibRefs = new ArrayList();
+		IVirtualReference [] libModules = getLibModules(component.getProject());
+		for(int i=0;i<libModules.length; i++){
+			IVirtualComponent comp = libModules[i].getReferencedComponent();
+			if(comp != null && comp.exists()){
+				if(comp.isBinary()){
+					otherExistingWebLibRefs.add(libModules[i]);
+				} else {
+					IProject p = comp.getProject();
+					if(p != null && p.exists()){
+						existingWebLibProjects.add(p);
 					}
-				} else if (item instanceof IVirtualComponent) {
-					utilProject = ((IVirtualComponent) item).getProject();
-					comp = (IVirtualComponent) item;
-				}
-				boolean existingEntry = false;
-				if (containerEntries != null) {
-					for (int j = 0; j < containerEntries.length; j++) {
-						IClasspathEntry eachEntry = containerEntries[j];
-						if (eachEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT && eachEntry.getPath().toString().equals("/" + utilProject.getName())) { //$NON-NLS-1$
-							IVirtualReference ref = component.getReference(utilProject.getName());
-							if (ref != null && ref.getRuntimePath().equals(libPath)) {
-								existingEntry = true;
-							}
-							break;
-						}
-					}
-				}
-				if( !existingEntry ){
-					IJavaProject javaProject = JavaCore.create( component.getProject() );
-					if( javaProject!= null ){
-						IClasspathEntry[] entry = javaProject.getRawClasspath();
-						for (int j = 0; j < entry.length; j++) {
-							IClasspathEntry eachEntry = entry[j];
-							if (eachEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT && 
-									eachEntry.getPath().toString().equals("/" + utilProject.getName())) { //$NON-NLS-1$
-								IVirtualReference ref = component.getReference(utilProject.getName());
-								if( ref != null && ref.getRuntimePath().equals( libPath )){
-									existingEntry = true;
-								}						
-								break;
-							}
-						}
-					}
-				}
-				
-				if (existingEntry) {
-					// build of map of all unique classpath component contributions from dependent projects
-					classPathWLPSelection.buildClasspathComponentDependencyMap(comp, pathToComp);
-				}
-				
-				classPathWLPSelection.createProjectElement(utilProject, existingEntry);
-				classPathWLPSelection.setFilterLevel(ClassPathSelection.FILTER_NONE);
-			}
-			
-			// add ClasspathElements for all dependent project cp dependencies
-			final Iterator it = pathToComp.values().iterator();
-			while (it.hasNext()) {
-				final IVirtualComponent c = (IVirtualComponent) it.next();
-				final URI archiveURI = URI.createURI(ModuleURIUtil.getHandleString(c));
-				String unresolvedURI = null;
-				try {
-					unresolvedURI = ModuleURIUtil.getArchiveName(archiveURI);
-				} catch (UnresolveableURIException e) {
-					e.printStackTrace();
-				}
-				if (unresolvedURI != null) {
-					final ClasspathElement element = classPathWLPSelection.createClasspathArchiveElement(c.getProject(), archiveURI, unresolvedURI);
-					classPathWLPSelection.addClasspathElement(element, unresolvedURI);
 				}
 			}
-
-			if (component != null && J2EEProjectUtilities.isDynamicWebProject( component.getProject()) && component instanceof J2EEModuleVirtualComponent) {
-				J2EEModuleVirtualComponent j2eeComp = (J2EEModuleVirtualComponent) component;
-				IVirtualReference[] newrefs = j2eeComp.getNonJavaReferences();
-				for (int i = 0; i < newrefs.length; i++) {
-					IVirtualReference ref = newrefs[i];
-					IVirtualComponent referencedComponent = ref.getReferencedComponent();
-					if (referencedComponent == null)
-						continue;
-					boolean isBinary = referencedComponent.isBinary();
-					if (isBinary) {
-						String unresolvedURI = ""; //$NON-NLS-1$
-						try {
-							unresolvedURI = ModuleURIUtil.getArchiveName(URI.createURI(ModuleURIUtil.getHandleString(referencedComponent)));
-						} catch (UnresolveableURIException e) {
-							e.printStackTrace();
-						}
-						
-						URI archiveURI = URI.createURI(unresolvedURI);
-
-						boolean alreadyInList = false;
-						Iterator iter = classPathWLPSelection.getClasspathElements().iterator();
-						while (iter.hasNext()) {
-							ClasspathElement tmpelement = (ClasspathElement) iter.next();
-							if (tmpelement.getText().equals(archiveURI.lastSegment())) {
-								alreadyInList = true;
-								break;
-							}
-						}
-						ClasspathElement element = null;
-						if (!alreadyInList) {
-							boolean inContainer = false;
-							if (containerEntries != null) {
-								String lastSegment = archiveURI.lastSegment();
-								for (int j = 0; !inContainer && j < containerEntries.length; j++) {
-									if (containerEntries[j].getPath().lastSegment().equals(lastSegment)) {
-										inContainer = true;
-									}
-								}
-							}
-							
-							if( !inContainer ){
-								IJavaProject javaProject = JavaCore.create( component.getProject() );
-									if( javaProject != null ){
-									VirtualArchiveComponent vComp = (VirtualArchiveComponent) referencedComponent;
-					                java.io.File diskFile = vComp.getUnderlyingDiskFile();
-					                IPath path = null;
-					                if ( diskFile.exists() ) {
-					                	path = new Path( diskFile.getAbsolutePath() );
-					                } else {
-					                    IFile iFile = vComp.getUnderlyingWorkbenchFile();
-					                    path = iFile.getFullPath();
-					                }								
-									inContainer=  inClassPath(javaProject, path );
-								}
-							}
-							if (inContainer) {
-								element = classPathWLPSelection.createArchiveElement(URI.createURI(ModuleURIUtil.getHandleString(referencedComponent)), referencedComponent.getName(), archiveURI.lastSegment());
-								classPathWLPSelection.addClasspathElement(element, unresolvedURI);
-							} else {
-								element = classPathWLPSelection.createArchiveElement(URI.createURI(ModuleURIUtil.getHandleString(referencedComponent)), archiveURI.lastSegment(), null);
-								classPathWLPSelection.addClasspathElement(element, unresolvedURI);
-							}
-						}
-					}
-				} // for
-				
-				// Add elements for raw classpath entries (either already tagged or potentially taggable) 
-				try {
-					classPathWLPSelection.createClasspathEntryElements(component, libPath);
-				} catch (CoreException ce) {
-					Logger.getLogger(J2EEPlugin.PLUGIN_ID).logError(ce);
-				}
-			}
-		} catch (CoreException e) {
-		} catch (Exception e) {
+		}
+		
+		//this is the list of all projects that should show up in the list
+		HashSet possibleWebLibs = new HashSet();
+		try{
+			List javaProjects = J2EEProjectUtilities.getAllJavaNonFlexProjects();
+			possibleWebLibs.addAll(javaProjects);
+		} catch(CoreException e){
 			Logger.getLogger().logError(e);
 		}
+		IProject[] utilityProjects = J2EEProjectUtilities.getAllProjectsInWorkspaceOfType(J2EEProjectUtilities.UTILITY);
+		possibleWebLibs.addAll(Arrays.asList(utilityProjects));
+		IProject[] ejbProjects = J2EEProjectUtilities.getAllProjectsInWorkspaceOfType(J2EEProjectUtilities.EJB);
+		possibleWebLibs.addAll(Arrays.asList(ejbProjects));
+		
+		Map pathToComp = new HashMap();
+		
+		//first handle the projects case
+		for(Iterator iterator = possibleWebLibs.iterator(); iterator.hasNext();){
+			IProject possibleWebLib = (IProject)iterator.next();
+			if(possibleWebLib.getName().startsWith(".")){ //$NON-NLS-1$
+				continue;
+			}
+			boolean isExistingWebLib = existingWebLibProjects.contains(possibleWebLib);
+			classPathWLPSelection.createProjectElement(possibleWebLib, isExistingWebLib);
+			// build of map of all unique classpath component contributions from dependent projects
+			if(isExistingWebLib){
+				IVirtualComponent component = ComponentCore.createComponent(possibleWebLib);
+				if(component != null){
+					classPathWLPSelection.buildClasspathComponentDependencyMap(component, pathToComp);
+				}
+			}
+		}
+		//next handle entries for all other web lib refs
+		//e.g. to jars in other projects, or outside the workspace or relative to a var
+		for(Iterator iterator = otherExistingWebLibRefs.iterator(); iterator.hasNext();){
+			IVirtualReference ref = (IVirtualReference)iterator.next();
+			IVirtualComponent referencedComponent = ref.getReferencedComponent();
+			// do not add if this is a classpath entry dependency
+			if (ClasspathDependencyUtil.isClasspathComponentDependency(referencedComponent)) {
+				continue;
+			}
+			try {
+				String unresolvedURI = ModuleURIUtil.getArchiveName(URI.createURI(ModuleURIUtil.getHandleString(referencedComponent)));
+				URI archiveURI = URI.createURI(unresolvedURI);
+				ClasspathElement element = classPathWLPSelection.createArchiveElement(URI.createURI(ModuleURIUtil.getHandleString(referencedComponent)), referencedComponent.getName(), archiveURI.lastSegment());
+				classPathWLPSelection.addClasspathElement(element, unresolvedURI);
+			} catch (UnresolveableURIException e) {
+				Logger.getLogger(J2EEPlugin.PLUGIN_ID).logError(e);
+			}
+		}
+		
+		// add ClasspathElements for all dependent project cp dependencies
+		final Iterator it = pathToComp.values().iterator();
+		while (it.hasNext()) {
+			final IVirtualComponent c = (IVirtualComponent) it.next();
+			final URI archiveURI = URI.createURI(ModuleURIUtil.getHandleString(c));
+			String unresolvedURI = null;
+			try {
+				unresolvedURI = ModuleURIUtil.getArchiveName(archiveURI);
+			} catch (UnresolveableURIException e) {
+				Logger.getLogger(J2EEPlugin.PLUGIN_ID).logError(e);
+			}
+			if (unresolvedURI != null) {
+				final ClasspathElement element = classPathWLPSelection.createClasspathArchiveElement(c.getProject(), archiveURI, unresolvedURI);
+				classPathWLPSelection.addClasspathElement(element, unresolvedURI);
+			}
+		}
+		
+		// Add elements for raw classpath entries (either already tagged or potentially taggable) 
+		try {
+			classPathWLPSelection.createClasspathEntryElements(component, WEBLIB);
+		} catch (CoreException ce) {
+			Logger.getLogger(J2EEPlugin.PLUGIN_ID).logError(ce);
+		}
 	}
 
 	public boolean isWLPModel() {
 		return isWLPModel;
 	}
-
+	/**
+	 * @deprecated do not use this method
+	 * @param isWLPModel
+	 */
 	public void setWLPModel(boolean isWLPModel) {
 		this.isWLPModel = isWLPModel;
 	}
 
-	private boolean inClassPath(IJavaProject javaProject, IPath path ){
-		boolean existingEntry = false;
-		IClasspathEntry[] entry = null;
-		try {
-			entry = javaProject.getRawClasspath();
-		} catch (JavaModelException e) {
-			Logger.getLogger().logError(e);
-		}
-		for (int j = 0; j < entry.length; j++) {
-			IClasspathEntry eachEntry = entry[j];
-			if (eachEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || eachEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE ) {
-				IClasspathEntry classPathEntry = JavaCore.getResolvedClasspathEntry( eachEntry );
-				if( classPathEntry != null && classPathEntry.getPath().equals(path) ){
-					existingEntry = true;
-					break;
-				}
-			}
-		}
-		return existingEntry;
-	}
 }
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 3ebddb1..ff978e0 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
@@ -42,14 +42,19 @@
 import org.eclipse.jst.jee.application.ICommonApplication;
 import org.eclipse.jst.jee.application.ICommonModule;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.wst.common.componentcore.ArtifactEdit;
 import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties;
+import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel;
 import org.eclipse.wst.common.componentcore.internal.ReferencedComponent;
 import org.eclipse.wst.common.componentcore.internal.StructureEdit;
 import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent;
 import org.eclipse.wst.common.componentcore.internal.operation.CreateReferenceComponentsOp;
+import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities;
 import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
 import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
+import org.eclipse.wst.common.internal.emfworkbench.validateedit.IValidateEditContext;
 import org.eclipse.wst.common.project.facet.core.IFacetedProject;
 import org.eclipse.wst.common.project.facet.core.IProjectFacet;
 import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -292,5 +297,23 @@
 			status = provider.validateEdit(null, context);
 		}
 		return status;
-	}	
+	}
+	
+	protected IStatus validateEdit() {
+		IStatus status = super.validateEdit();
+		if (status.isOK()) {
+			IValidateEditContext validator = (IValidateEditContext) UIContextDetermination.createInstance(IValidateEditContext.CLASS_KEY);
+			IVirtualComponent sourceComp = (IVirtualComponent) model.getProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT);
+			IProject project = sourceComp.getProject();
+			ArtifactEdit edit = null;
+			try {
+				edit = ComponentUtilities.getArtifactEditForWrite(sourceComp);
+				status = validator.validateState((EditModel) edit.getAdapter(ArtifactEditModel.ADAPTER_TYPE));
+			} finally {
+				if (edit != null)
+					edit.dispose();
+			}
+		}
+		return status;
+	}
 }