Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Starting Eclipse Commandline With Equinox Launcher

Revision as of 12:37, 3 July 2008 by Codeslave.ca.ibm.com (Talk | contribs) (add note about JUnit tests)

Launching Eclipse with the new Equinox jar is as easy as A, B, C.

Note that the initial releases of Eclipse 3.3 on Windows have a configuration bug preventing the following approach from working. See this mail thread for details.

If you're looking to run JUnit tests headlessly, here's a bash script that does that as part of a headless PDE build. Relevant part starts at line 200:

# run tests
echo "[runtests] [`date +%H\:%M\:%S`] Launching Eclipse (installmode = $installmode with -enableassertions turned on) ..."
execCmd "$JAVA_HOME/bin/java $Xflags -enableassertions -cp $cpAndMain -ws $ws -os $os -arch $arch \
-application org.eclipse.ant.core.antRunner -data $workspaceDir -file test.xml $antTestTarget \
$Dflags -Dws=$ws -Dos=$os -Darch=$arch -D$installmode=true $J2SE15flags \
$properties -logger org.apache.tools.ant.DefaultLogger" $consolelog;
echo "[runtests] [`date +%H\:%M\:%S`] Eclipse test run completed. "

Ant Script

 <!-- set path to eclipse folder. If local folder, use '.'; otherwise, use c:\path\to\eclipse or /path/to/eclipse/ -->
 <property name="eclipse.home" value="."/>

 <!--  get path to equinox jar inside ${eclipse.home} folder (copy/rename actual jar) -->
 <copy tofile="${eclipse.home}/eclipse/plugins/org.eclipse.equinox.launcher.jar">
   <fileset dir="${eclipse.home}/eclipse/plugins"
     includes="**/org.eclipse.equinox.launcher_*.jar"/>
 </copy>

 <!-- start Eclipse w/ java -->
 <java classpath="${eclipse.home}/eclipse/plugins/org.eclipse.equinox.launcher.jar"
 .../>

Or, if you are using Ant 1.7 and don't like copying resources around (or don't have permission to do so) this appears to work to set the path to the newest available equinox launcher jar in a property for later use:

 <!-- set path to eclipse folder. If local folder, use '.'; otherwise, use c:\path\to\eclipse or /path/to/eclipse/ -->
 <property name="eclipse.home" value="."/>

 <!-- store path to newest launcher JAR in path id 'newest.equinox.launcher.path.id' -->
 <path id="newest.equinox.launcher.path.id">
   <first count="1">
     <sort>
       <fileset dir="${eclipse.home}/eclipse/plugins" includes="**/org.eclipse.equinox.launcher_*.jar"/>

       <!-- Seems the default order is oldest > newest so we must reverse it.
            The 'reverse' and 'date' comparators are in the internal antlib
            org.apache.tools.ant.types.resources.comparators.
         -->
       <reverse xmlns="antlib:org.apache.tools.ant.types.resources.comparators">
         <!-- 'date' inherits 'reverse's namespace -->
         <date/>
       </reverse>
     </sort>
   </first>
 </path>

 <!-- turn the path into a property -->
 <property name="equinox.launcher.jar.location" refid="newest.equinox.launcher.path.id" />

 <!-- you can now reference the jar through the property ${equinox.launcher.jar.location} -->
 <echo message="Using equinox launcher jar: ${equinox.launcher.jar.location}" />

Bash Shell Script

 #!/bin/bash

 # set path to eclipse folder. If local folder, use '.'; otherwise, use /path/to/eclipse/
 eclipsehome=".";

 # get path to equinox jar inside $eclipsehome folder
 cp=$(find $eclipsehome -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);

 # start Eclipse w/ java
 /opt/java50/bin/java -cp $cp org.eclipse.equinox.launcher.Main ...

Cmd/Bat Script

Save this as eclipse.cmd. This has been tested with Windows XP Pro (SP2).

 @echo off

 :: set path to eclipse folder. If local folder, use '.'; otherwise, use c:\path\to\eclipse
 set ECLIPSEHOME=.
 
 :: get path to equinox jar inside ECLIPSEHOME folder
 for /f "delims= tokens=1" %%c in ('dir /B /S /OD %ECLIPSEHOME%\plugins\org.eclipse.equinox.launcher_*.jar') do set EQUINOXJAR=%%c
 
 :: start Eclipse w/ java
 echo Using %EQUINOXJAR% to start up Eclipse...
 java -jar %EQUINOXJAR% ...

Copyright © Eclipse Foundation, Inc. All Rights Reserved.