Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Add directory to PATH environment variable, globally and programmatically(PATH environment variable)
Add directory to PATH environment variable, globally and programmatically [message #1278740] Thu, 27 March 2014 19:47 Go to next message
John Moule is currently offline John MouleFriend
Messages: 9
Registered: March 2014
Junior Member
Hi,

Can anyone tell me the best way to add a directory to the global system PATH environment programmatically, either in java or statically, perhaps in plugin_customization.ini?

(See attached source)
I have used this to append the environment

UserDefinedEnvironmentSupplier udes = EnvironmentVariableManager.fUserSupplier

but I don't think its the right approach. Once set changes to the underlying environment set outside Eclipse don't get reflected when you restart with the same workspace. I just want something to append my PATH version to the global, system PATH version.

Any suggestions appreciated.

cheers john

Re: Add directory to PATH environment variable, globally and programmatically [message #1282580 is a reply to message #1278740] Wed, 02 April 2014 14:25 Go to previous messageGo to next message
John Moule is currently offline John MouleFriend
Messages: 9
Registered: March 2014
Junior Member
I solved this. In case anyone is wondering this is my solution:

    import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
    import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
    import org.eclipse.cdt.internal.core.envvar.UserDefinedEnvironmentSupplier;
    import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;

    ...


      /**
       * Add a path to the beginning of the PATH environment variable.
       * This path is not persisted so its ok to perform this on every
       * startup. The existing system PATH is maintained.
       * Note:
       * 1) the PATH modification does not appear in Environment preference page 
       * (Window > Preferences > C/C++ > Build > Environment)! Rather it appears
       * in every project property >  C/C++ Build > Environment > PATH variable.
       * 2) each call to this method overwrites previous values in PATH. If multiple
       * paths are to be prepended they should be concatenated in a single call.
       * 
       * @param path The directory or directories to prepend, separated with the
       * relevant path delimiter.
       */
      public  static void prependToSystemPath(String path) {
        EnvironmentVariableManager.fUserSupplier.createOverrideVariable("PATH", path,
            IBuildEnvironmentVariable.ENVVAR_PREPEND,
            EnvironmentVariableManager.getDefault().getDefaultDelimiter());
      }	



and I use it thus:

      prependToSystemPath("c:\mypath1;c:\mypath2");


The benefit is this code can be called everytime Eclipse starts (I use <extension point="org.eclipse.ui.startup">) and each time it will prepend my path to whatever system path is defined at that time. This means, for example, you can use a workspace on Windows during one Eclipse session and then subsequently use the same workspace on a Linux system and the system path is reset for each start.
Re: Add directory to PATH environment variable, globally and programmatically [message #1283379 is a reply to message #1282580] Thu, 03 April 2014 10:55 Go to previous message
Klaus km is currently offline Klaus kmFriend
Messages: 142
Registered: November 2011
Senior Member
Hi,

i use a batch file (on Windows), works like a charm.

@echo off
PATH=C:\mingw64\bin;%PATH%
start eclipse.exe


One can use different batches to select different compiler paths if needed.

regards,
Klaus


Previous Topic:running CDT indexer from commandline
Next Topic:"Add include" does not work
Goto Forum:
  


Current Time: Fri Apr 19 19:46:16 GMT 2024

Powered by FUDForum. Page generated in 0.03086 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top