问题
Situation
I have developed an Eclipse RCP application. This application may be installed on both Windows and Linux systems.
If this application is installed in Administrator mode (Windows) or by a superuser (Linux), the application is typically installed in a write-protected shared install directory.
- On Windows, our product installer is always run in Administrator-mode. The default installation directory is the (write-protected)
C:\Program Files\MyProduct. - On Linux, the installer can be run by both a normal user and a superuser. For a superuser the default installation directory is the (also write-protected)
/opt/MyProduct.
This is what Eclipse itself calls a shared install.
Obviously, a normal user running the application does not have rights to modify this directory. Therefore, runtime data such as changed configuration data or auto-updated plug-ins are written to a user-specific private configuration area.
- On Windows this defaults to a subdirectory of
$USERPROFILE\.eclipse\. - On Linux this also defaults to a subdirectory of
~/.eclipse/
Problem
By default the private directory within .eclipse has a seemingly random name:
.eclipse/1410846118
If I add an .eclipseproduct metadata file, the default behaviour changes. The content of the file is described in this forum post:
# FILE:
name=MyProduct
id=com.mycompany.myproduct.gui.product
version=1.8.17
This results in a private directory with the following name:
.eclipse/com.mycompany.myproduct.gui.product_1.8.17_1410846118/
This means although the product ID and version are now used, the same seemingly random number is still present as a suffix.
My question is simple: what is this number and how can I calculate it?
Eclipse seems to be able to calculate it after installation. However, I don't seem to find it in any file of the shared installation using
sudo find /opt/MyProduct -name '*' | xargs grep -e '1410846118'
回答1:
The code for this seems to be in org.eclipse.core.runtime.adaptor.LocationManager. This looks for the product id in a file called .eclipseproduct in the installation directory. If the file does not exist it uses the hash code of the install directory path which is presumably what you are seeing.
So I think you need an .eclipseproduct file. See Define .eclipseproduct during build for some more information.
Edit:
Even with the product file the hash code is still appended. The hash is calculated using this:
File installDir = path of install directory from osgi.install.area
int hashCode;
try {
hashCode = installDir.getCanonicalPath().hashCode();
} catch (IOException ioe) {
// fall back to absolute path
hashCode = installDir.getAbsolutePath().hashCode();
}
if (hashCode < 0)
hashCode = -(hashCode);
String installDirHash = String.valueOf(hashCode);
来源:https://stackoverflow.com/questions/18570638/eclipse-rcp-how-is-the-default-name-of-the-private-configuration-directory-cre