[252077] [hotbug] Fail to deploy an EAR project if it contains a module
diff --git a/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/command/common/AddModuleToServerCommand.java b/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/command/common/AddModuleToServerCommand.java
index 8f0b58a..6f0f37f 100644
--- a/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/command/common/AddModuleToServerCommand.java
+++ b/bundles/org.eclipse.jst.ws.consumption/src/org/eclipse/jst/ws/internal/consumption/command/common/AddModuleToServerCommand.java
@@ -12,6 +12,8 @@
  * 20060921 [158210] kathy@ca.ibm.com - Kathy Chan, Calling incremental build on the project before adding to server
  * 20080415   227237 gilberta@ca.ibm.com - Gilbert Andrews
  * 20090311 250984   mahutch@ca.ibm.com - Mark Hutchinson, Use another mechanism to wait for build to be completed
+ * 20090518 [252077] tangg@emc.com - Gary Tang, Fail to deploy an EAR project if it contains a module
+ *                   kchong@ca.ibm.com - Keith Chong, (updated patch)
  *******************************************************************************/
 
 package org.eclipse.jst.ws.internal.consumption.command.common;
@@ -71,7 +73,9 @@
 	    IProject iproject = ProjectUtilities.getProject(project);
 	    if (!J2EEUtils.isJavaComponent(iproject))
 	    {      
-	    	IModule imodule = ServerUtils.getModule(iproject);
+        // Get the IModule as specified by the module name
+        IModule imodule = ServerUtils.getModule(iproject, module);
+
 	    	// TODO:  This workaround for 156768 should be removed once the defect is fixed
 	    	if (imodule == null) {
 	    	    // calling incremental build on the project before trying again
@@ -134,6 +138,4 @@
 	{
 		this.serverInstanceId = serverInstanceId;
 	}	
-
-	
 }
diff --git a/bundles/org.eclipse.jst.ws/src/org/eclipse/jst/ws/internal/common/ServerUtils.java b/bundles/org.eclipse.jst.ws/src/org/eclipse/jst/ws/internal/common/ServerUtils.java
index 087d515..d13a8a2 100644
--- a/bundles/org.eclipse.jst.ws/src/org/eclipse/jst/ws/internal/common/ServerUtils.java
+++ b/bundles/org.eclipse.jst.ws/src/org/eclipse/jst/ws/internal/common/ServerUtils.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -13,6 +13,8 @@
  * 20060330   124667 kathy@ca.ibm.com - Kathy Chan
  * 20061004   159356 kathy@ca.ibm.com - Kathy Chan, Get correct module root URL based on server chosen
  * 20070119   159458 mahutch@ca.ibm.com - Mark Hutchinson
+ * 20090518 [252077] tangg@emc.com - Gary Tang, Fail to deploy an EAR project if it contains a module
+ *                   kchong@ca.ibm.com - Keith Chong, (updated patch)
  *******************************************************************************/
 
 package org.eclipse.jst.ws.internal.common;
@@ -396,6 +398,27 @@
 	public static IModule getModule(IProject project) {
 	return ServerUtil.getModule(project);
 }
+	/**
+	 * Find the specific module with module name in a project
+	 * @param project - the project
+	 * @param module - name of desired module
+	 * @return IModule
+	 */
+	public static IModule getModule(IProject project, String module) {
+		// If module is null, then just return the first one
+		if (module == null)
+			return getModule(project);
+		
+		IModule[] modules = ServerUtil.getModules(project);
+		int length = modules.length;
+		for (int i = 0; i < length; i++)
+		{
+			IModule aModule = modules[i];
+			if (module.equals(aModule.getName()))
+				return aModule;
+		}
+		return null;
+	}
 	
 // Workaround for 113621
 //public static IModule getModule(IProject project) {