Index: ProjectExtension.java
===================================================================
--- ProjectExtension.java	(revision 41311)
+++ ProjectExtension.java	(revision 41312)
@@ -25,7 +25,6 @@
 
 import java.awt.Component;
 import java.io.File;
-import java.lang.reflect.InvocationTargetException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -37,11 +36,15 @@
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.commons.io.FilenameUtils;
+import org.gvsig.tools.util.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
 import org.gvsig.andami.IconThemeHelper;
 import org.gvsig.andami.Launcher;
 import org.gvsig.andami.Launcher.TerminationProcess;
 import org.gvsig.andami.PluginServices;
+import org.gvsig.andami.PluginsLocator;
+import org.gvsig.andami.actioninfo.ActionInfo;
+import org.gvsig.andami.actioninfo.ActionInfoManager;
 import org.gvsig.andami.messages.NotificationManager;
 import org.gvsig.andami.plugins.Extension;
 import org.gvsig.andami.plugins.IExtension;
@@ -51,14 +54,13 @@
 import org.gvsig.andami.ui.mdiManager.IWindow;
 import org.gvsig.andami.ui.mdiManager.WindowInfo;
 import org.gvsig.andami.ui.wizard.UnsavedDataPanel;
-import org.gvsig.app.ApplicationLocator;
-import org.gvsig.app.ApplicationManager;
 import org.gvsig.app.project.Project;
 import org.gvsig.app.project.ProjectManager;
 import org.gvsig.app.project.documents.gui.ProjectWindow;
 import org.gvsig.app.project.documents.view.ViewManager;
 import org.gvsig.gui.beans.swing.JFileChooser;
 import org.gvsig.tools.ToolsLocator;
+import org.gvsig.tools.dataTypes.DataTypes;
 import org.gvsig.tools.extensionpoint.ExtensionPointManager;
 import org.gvsig.tools.persistence.exception.PersistenceException;
 import org.gvsig.utils.GenericFileFilter;
@@ -66,6 +68,7 @@
 import org.gvsig.utils.save.BeforeSavingListener;
 import org.gvsig.utils.save.SaveEvent;
 import org.gvsig.utils.swing.threads.IMonitorableTask;
+import sun.misc.Launcher;
 
 /**
  * Extension que proporciona controles para crear proyectos nuevos, abrirlos y
@@ -99,24 +102,15 @@
 
 	private List<AfterSavingListener> afterSavingListeners = new ArrayList<AfterSavingListener>();
 
-	/**
-	 * @see com.iver.mdiApp.plugins.IExtension#initialize()
-	 */
-	public void initialize() {
-		// try {
-		// Class.forName("javax.media.jai.EnumeratedParameter");
-		// } catch (ClassNotFoundException e) {
-		// NotificationManager
-		// .addError(
-		// "La máquina virtual con la que se ejecuta gvSIG no tiene JAI instalado",
-		// e);
-		// }
+        public void initialize() {
+            initializeDocumentActionsExtensionPoint();
+            registerDocuments();
+            registerIcons();
+            PluginsLocator.getManager().addStartupTask(
+                    "Open project",
+                    new OpenInitialProjectTask(), true, 1000);
+        }
 
-		initializeDocumentActionsExtensionPoint();
-		registerDocuments();
-		registerIcons();
-	}
-
 	private void registerIcons() {
 		IconThemeHelper.registerIcon("action", "application-project-new", this);
 		IconThemeHelper
@@ -129,10 +123,46 @@
 		IconThemeHelper.registerIcon("project", "project-icon", this);
 	}
 
+        private class OpenInitialProjectTask implements Runnable {
+            public void run() {
+                File pf = getInitialProjectFile();
+                if (pf == null) {
+                    LOG.info("No initial file opened.");
+                    return;
+                }
+                ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
+                ActionInfo action = actionManager.getAction("application-project-open");
+                action.execute(pf);
+            }
+            /**
+             * Returns the file to be opened or null if no parameter
+             * or file does not exist
+             * 
+             * @return
+             */
+            private File getInitialProjectFile() {
+                String[] theArgs = PluginServices.getArguments();
+                String lastArg = theArgs[theArgs.length - 1];
+                if ( StringUtils.isEmpty(lastArg) ) {
+                    return null;
+                }
+                if( lastArg.startsWith("-") ) {
+                    return null;
+                }
+                if (!lastArg.toLowerCase().endsWith(Project.FILE_EXTENSION.toLowerCase())) {
+                    LOG.info("Do not open project file, does not have the expected extension '" + 
+                            Project.FILE_EXTENSION +"' ("+lastArg+").");
+                    return null;
+                }
+                File projectFile = new File(lastArg);
+                if ( !projectFile.exists()) {
+                    LOG.info("Do not open project file, '" +projectFile.getAbsolutePath() + "' do not exist.");
+                    return null;
+                }
+                return projectFile;
+            }   
+        }
 
-
-
-
 	public ProjectWindow getProjectFrame() {
 		if (projectFrame == null) {
 			projectFrame = new ProjectWindow();
@@ -262,7 +292,7 @@
 	public void execute(String command) {
 		this.execute(command, null);
 	}
-
+        
 	public void execute(String actionCommand, Object[] args) {
 		if (actionCommand.equals("application-project-new")) {
 			if (!askSave()) {
@@ -270,33 +300,25 @@
 			}
 
 			projectPath = null;
-			// ProjectDocument.initializeNUMS();
 			PluginServices.getMDIManager().closeAllWindows();
 			setProject(ProjectManager.getInstance().createProject());
 			getProjectFrame().setProject(p);
 			showProjectWindow();
 			PluginServices.getMainFrame().setTitle(
 					PluginServices.getText(this, "sin_titulo"));
-		} else if (actionCommand.equals("application-project-open")) {
+
+                } else if (actionCommand.equals("application-project-open")) {
 			if (!askSave()) {
 				return;
 			}
-			File projectFile = null;
+                        File projectFile = (File) ArrayUtils.get(args, 0, DataTypes.FILE);
+                        if ( projectFile != null && !projectFile.exists() ) {
+                            LOG.warn("Can't load project '"
+                                    + projectFile.getAbsolutePath()
+                                    + "', file not exist.");
+                            projectFile = null;
+                        }
 
-			if (args != null && args.length > 0 && args[0] != null) {
-				if (args[0] instanceof File) {
-					projectFile = (File) args[0];
-				} else if (args[0] instanceof String) {
-					projectFile = new File((String) args[0]);
-					if (!projectFile.exists()) {
-						LOG.warn("Can't load project '"
-								+ projectFile.getAbsolutePath()
-								+ "', file not exist.");
-						projectFile = null;
-					}
-				}
-			}
-
 			if (projectFile == null) {
 				Preferences prefs = Preferences.userRoot().node(
 						"gvsig.foldering");
@@ -334,14 +356,7 @@
 		} else if (actionCommand.equals("application-project-save")) {
 			saveProject();
 		} else if (actionCommand.equals("application-project-save-as")) {
-			File file = null;
-			if (args != null && args.length > 0 && args[0] != null) {
-				if (args[0] instanceof File) {
-					file = (File) args[0];
-				} else if (args[0] instanceof String) {
-					file = new File((String) args[0]);
-				}
-			}
+			File file = (File) ArrayUtils.get(args, 0, DataTypes.FILE);
 			saveAsProject(file);
 		}
 
