It seems that you're not asking about locating the Eclipse installation itself, but about locating some other program.
In such an event, you have two problems. One, your code will be platform-specific, and two, there is no guaranteed way to do this for arbitrary programs. Based on your post, I am assuming you're interested in Windows.
If you know that the program is in the PATH system variable, you can use the where
command. where.exe someappinpath.exe
will return the path on current Windows versions. To actually execute the command from Java, you can use a simple Runtime.getRuntime().exec()
call, or see this question for better ways of doing it.
If the program cannot be expected to be in PATH, it is good if you know what it writes to the Windows Registry. Then you could, under HKCU\Software
, or under HKLM\Software
, possibly locate the application's data and installation location. Again, this requires knowing what the application saves in the Registry.
Looking through SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
under both HKCU
and HKLM
will provide you information about all programs that have written uninstall information. Unfortunately, some programs do not do this, but if that is the case, you cannot really count on anything.
As a last resort, you could search the drives for a file matching the program executable's name. This is not a good method, it's slow and you risk finding the wrong file.
From a purely practical perspective, if your plugin relies on some 3rd-party program, I would first try to locate the program automatically (through where
or looking up the known Registry key, or the default installation location) and if that fails, ask the user to point out the program's location.