Eclipse OSGI 配置:相对路径和/或 @config.dir 之类的替换?

发布于 2024-10-16 19:10:43 字数 825 浏览 6 评论 0 原文

在我的 RCP 应用程序中,我想将属性 (osgi.java.profile) 指向一个文件,并且更喜欢使用相对于我的安装和配置目录的路径。

config.ini 中支持哪些类型的变量有明确的规范吗?


@config.dir 似乎受支持,内置中有参考,并且总是将其作为典型示例提及(例如 这个答案) 但是,查看 Eclipse help/运行时选项,它提到了一些“符号位置”,例如@user.home;然而,这似乎相当有限,并且不包括@config.dir。

甚至还深入研究了 org.eclipse.osgi 源代码,但没有发现对此的引用(我确实找到了 LocationManager 及其对 @user.dir & co 的硬编码变量替换)。 我可以以某种方式引用任意系统属性吗?

这个@config.dir是一个特殊情况,仅由P2处理吗? 更新:情况似乎是这样..查看Eclipse SDK,关于..配置对话框显示@config.dir未解析,可能是由Equinox字面意思理解的..

感谢您的任何提示。

In my RCP app, I would like to point a property (osgi.java.profile) to a file, and would prefer using paths relative to my installation and config dir.

Is there a definitive spec on what kind of variables are supported in config.ini?


@config.dir seems to be supported, there are references in the builtin, and it's always mentioned as typical example (e.g this SO answer )
However, looking at docs like Eclipse help/Runtime Options, it mentions a few "symbolic locations" like @user.home; however that seems fairly limited and doesn't include @config.dir.

Have even dug into org.eclipse.osgi sources as well, and found no references to this (I did find LocationManager and its hard coded variable substitutions for @user.dir & co).
Can I refer to arbitrary system properties there in some way?

Is this @config.dir a special case, only handled by P2? UPDATE: this seems to be the case.. looking at Eclipse SDK, About .. Configuration dialog shows @config.dir unresolved, probably taken literally by the Equinox..

Thanks for any hints.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

っ〆星空下的拥抱 2024-10-23 19:10:43

我参加聚会迟到了,但希望这能对其他人有所帮助。

从 Eclipse 3.8/4.2(2012 年 6 月)开始,您可以将 Java 属性和环境变量替换到 config.ini 文件中 (Eclipse 错误 241192)。 Equinox 启动程序不支持 eclipse.ini 启动程序文件中的替换。语法使用美元符号($VARIABLE$)来指示变量替换:

osgi.configuration.area=$APPDATA$/MyCompany/MyProgram/configuration
osgi.user.area=$APPDATA$/MyCompany/MyProgram/user
osgi.instance.area=$APPDATA$/MyCompany/MyProgram/instance

我想您可以使用类似的东西来达到您的目的:

osgi.java.profile=$osgi.install.area$/path/to/profile.txt

I'm late to the party, but hopefully this will help others in the future.

Starting with Eclipse 3.8/4.2 (June 2012), you can substitute Java properties and environment variables into your config.ini file (Eclipse Bug 241192). The Equinox launcher does not support substitution in the eclipse.ini launcher file. The syntax uses dollar signs ($VARIABLE$) to indicate variable substitution:

osgi.configuration.area=$APPDATA$/MyCompany/MyProgram/configuration
osgi.user.area=$APPDATA$/MyCompany/MyProgram/user
osgi.instance.area=$APPDATA$/MyCompany/MyProgram/instance

I imagine you could use something like this for your purposes:

osgi.java.profile=$osgi.install.area$/path/to/profile.txt
提赋 2024-10-23 19:10:43

您可以使用平台 URL (平台 URI 方案)来实现此目的,即

osgi.java.profile = platform:/config/java_profile.txt

config.ini 中,将指向文件 java_profile.txt当前配置目录。

您还可以使用 config.ini 中的现有系统属性:

osgi.java.profile = ${osgi.configuration.area}/java_profile.txt

You can use a platform URL (Platform URI scheme) to achieve this, i.e.

osgi.java.profile = platform:/config/java_profile.txt

in config.ini, would point to the file java_profile.txt in the current configuration directory.

You might also use existing system properties in config.ini:

osgi.java.profile = ${osgi.configuration.area}/java_profile.txt
笨死的猪 2024-10-23 19:10:43

来自 org.eclipse.core.runtime.adaptor.LocationManager,以下是特殊标记:

    // Data mode constants for user, configuration and data locations.                                                                                          
    private static final String NONE = "@none"; //$NON-NLS-1$                                                                                                   
    private static final String NO_DEFAULT = "@noDefault"; //$NON-NLS-1$                                                                                        
    private static final String USER_HOME = "@user.home"; //$NON-NLS-1$                                                                                         
    private static final String USER_DIR = "@user.dir"; //$NON-NLS-1$                                                                                           

From org.eclipse.core.runtime.adaptor.LocationManager, here are the special tokens:

    // Data mode constants for user, configuration and data locations.                                                                                          
    private static final String NONE = "@none"; //$NON-NLS-1$                                                                                                   
    private static final String NO_DEFAULT = "@noDefault"; //$NON-NLS-1$                                                                                        
    private static final String USER_HOME = "@user.home"; //$NON-NLS-1$                                                                                         
    private static final String USER_DIR = "@user.dir"; //$NON-NLS-1$                                                                                           
浮世清欢 2024-10-23 19:10:43

为什么不使用两个系统属性变量?

一种名为-Dmy.relativepath=filename,由您的eclipse安装文件夹(工作空间或任何地方)相对路径的代码处理,另一种名为-Dmy.path=absolutepath代码>.

系统属性被传递给jvm,如果你想在其值中使用变量,你需要在本机启动器(如eclipse.exe)中使用一些技巧(在运行时翻译变量)。

Why not use two system property variables?

One is named -Dmy.relativepath=filename, which is processed by your code of relative path of eclipse installation folder(workspace or anywhere), another is called -Dmy.path=absolutepath.

The system property is passed to the jvm, you need some tricky(translate the variable in runtime) in the native launcher(like eclipse.exe) if you wants to use variable in its value.

末骤雨初歇 2024-10-23 19:10:43

看看 osgi.java.profile 在 org.eclipse.osgi.framework.internal.core.Framework 中是如何解析的:

// check for the java profile property for a url
String propJavaProfile = FrameworkProperties.getProperty(Constants.OSGI_JAVA_PROFILE);
if (propJavaProfile != null)
    try {
        // we assume a URL
        url = new URL(propJavaProfile);
    } catch (MalformedURLException e1) {
        // try using a relative path in the system bundle
        url = findInSystemBundle(propJavaProfile);
    }

这意味着 osgi.java.profile 必须指向一个完全限定的 URL,或者指向一个系统包中的相对路径 (org.eclipse.osgi)。这使得在不修补 Eclipse 的情况下无法使用安装目录相对路径。

Look how osgi.java.profile is resolved in org.eclipse.osgi.framework.internal.core.Framework:

// check for the java profile property for a url
String propJavaProfile = FrameworkProperties.getProperty(Constants.OSGI_JAVA_PROFILE);
if (propJavaProfile != null)
    try {
        // we assume a URL
        url = new URL(propJavaProfile);
    } catch (MalformedURLException e1) {
        // try using a relative path in the system bundle
        url = findInSystemBundle(propJavaProfile);
    }

That means osgi.java.profile must point either to a fully qualified URL, or to a relative path in system bundle (org.eclipse.osgi). This makes impossible usage of installation directory relative path without patching Eclipse.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文