java – how to run Eclipse -clean on a Mac?-ThrowExceptions

Exception or error:

I can run eclipse -clean on my PC, but on my Mac, the executable is Eclipse.app — how do you run that with arguments on the command-line?

How to solve:

If you CD to the eclipse installation directory using terminal, then you will see there is a directory called eclipse.app. CD to Eclipse.app\Contents\MacOS under that directory there should be an executable called eclipse.

I believe you can launch eclipse from the commandline by executing the eclipse executable with the -clean argument, as below:

./eclipse -clean

Answer:

Quote: “On Mac OS X, you start Eclipse by double clicking the Eclipse application. If you need to pass arguments to Eclipse, you’ll have to edit the eclipse.ini file inside the Eclipse application bundle: select the Eclipse application bundle icon while holding down the Control Key. This will present you with a popup menu. Select “Show Package Contents” in the popup menu. Locate eclipse.ini file in the Contents/MacOS sub-folder and open it with your favorite text editor to edit the command line options.”

Find more here: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Frunning_eclipse.htm

Answer:

Here is a script using macports to automate the restart. You can put this script e.g. on your desktop to be able to double click it.

#!/bin/bash
# WF 2014-03-14
# start Eclipse cleanly
pgrep -fl Eclipse.app
if [ $? -eq 0 ]
then
  echo "Eclipse is running - shall i kill and restart it with -clean? y/n?"
  read answer
  case $answer in
    y|Y) ;;
    *) echo "ok - I'm aborting this ..."
    exit 1;
    ;;
  esac
  echo "killing current eclipse"
  pkill -f Eclipse.app
fi
echo "starting eclipse cleanly ..."
/Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse -clean -clearPersistedState&

Answer:

I had this problem earlier today. When I would try to run clean option it still wouldn’t finish building the workspace. I found that if I removed the .metadata file from the workspace it would create a brand new workspace and even launch the initial welcome screen. Warning this will remove all of your builds, and all information from your workspace in eclipse, however it will remain intact in your finder folder which you can later import from with a little finagling.

Answer:

Geesh everyone. If you have a path to it, great, the command line works as above. Otherwise, navigate to the enclosing folder of your Eclipse, then into Eclipse.app and execute the following:

./eclipse -clean -vmargs -XstartOnFirstThread

This will not let your command window exit gracefully so you’ll have to kill the command window after doing it.

(But to be sure, clean doesn’t always work.)

EDIT: I should have edited this the next day! It blew out my workspaces – primarily because of the shared commands. All sorts of Errors.

What I did to resolve (instead of a reinstall): I restored a backup of the entire Eclipse Directory from a few days before and refreshed the projects. It took some doing. Not pretty.

Leave a Reply

Your email address will not be published. Required fields are marked *