无法从 Java 项目访问 Eclipse 插件中的类

发布于 2024-11-09 07:30:14 字数 575 浏览 0 评论 0原文

简而言之,我的问题如下:我想从 Java 项目访问 Eclipse 插件中包含的类。是否可以?我已将该类包含在插件的“导出的包”中,据说是“该插件向客户端公开的所有包”。我的 Java 项目可以作为“客户端”还是只有其他插件可以作为客户端?

更具体地说,我在使用 XText 时遇到了这个问题。我为一种语言构建了一个编辑器,用这种语言编写的程序以基于文本的格式存储,该格式遵循 XText 定义的语法。

我希望我的用户能够编写加载和操作这些基于 xtext 的文件的 Java 程序。为此,他们需要访问 XText 在插件项目中生成的所有类。但是,我无法使用这些类:在使用编辑器运行插件的 Eclipse 实例中,这些类不可见。

我怎样才能访问它们?我找到的唯一解决方案是将我的插件导出为 jar,然后将其包含在另一个 Eclipse 实例中的 Java 项目的构建路径中,但这听起来不太优雅。

看待这个问题的另一种方法如下:我希望某个类可用于在加载特定插件的 Eclipse 实例中构建的任何 Java 项目。我该怎么做呢?

感谢您的帮助。

附言。我正在从第一个 Eclipse 实例中启动第二个 Eclipse 实例(加载插件的实例)。

In abstract, my problem is the following: I want to access a class contained in an Eclipse plugin from a Java Project. Is it possible? I've included that class in the "Exported Packages" of the plugin, which supposedly are "all the packages that this plug-in exposes to clients." Can my Java project be a "client" or only other plugins can be clients?

More concretely, I've encountered this problems when using XText. I built an editor for a language, and programs written with this language are stored in a text based format that follows the grammar defined with XText.

I want my users to be able to write Java programs that load and manipulate those xtext-based files. For that, they need to access all the classes that XText generated in the plugin project. However, I haven't been able to use those classes: in an Eclipse instance that is running the plugin with my editor, those classes are not visible.

How can I access them? The only solution I've found is to export my plugin as a jar and then include it in the Build Path of the Java project, in the other Eclipse instance, but this doesn't sound elegant.

Another way of looking at this problem is the following: I want a certain class to be available to any Java project built in an Eclipse instance where a certain plugin is loaded. How can I do it?

Thanks for your help.

PS. I'm launching the second Eclipse instance (the one where the plugin is loaded) from within the first Eclipse instance.

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

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

发布评论

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

评论(1

呆橘 2024-11-16 07:30:14

生成 XText 支持后,您需要通过编辑 MANIFEST.MF 来确保从 Runtime 选项卡导出每个包。

然后,一旦您将插件部署到 Eclipse 中,该 Eclipse 环境将能够看到这些类。

但这只会帮助其他插件开发人员。 Java 应用程序可以看到类路径中存在的类(例如,如果添加插件 jar),但由于大多数 Eclipse 插件依赖于 Eclipse 生命周期来工作,因此它们的 Java 程序不太可能运行。情况并非总是如此(您可以在不运行 Eclipse 的情况下使用 JFace),但仅适用于专门以这种方式设计的插件。

如果您的插件已安装,您可以创建一个 java 项目并使用 *ECLIPSE_HOME* 变量将插件 jar 添加为外部 jar。如果您的插件是工作区中的一个项目,您可以像另一个 java 项目一样依赖它(从 java 构建路径)。但由于它是一个插件,因此可能无法帮助它们运行。

Once you generate your XText support, you need to make sure every package is exported from the Runtime tab by editing your MANIFEST.MF.

Then once you deploy your plugins into an eclipse, that eclipse environment will be able to see those classes.

But that would only help other plugin developers. Java apps can see classes that exist on the classpath (if you add the plugin jars, for example) but as most eclipse plugins depend on the eclipse lifecycle to work, it's unlikely that their java programs would run. That's not always the case (you can use JFace without a running eclipse) but only for plugins specifically designed that way.

If your plugin is installed, you can create a java project and add the plugin jar as an external jar, using *ECLIPSE_HOME* variable. If your plugin is a project in the workspace, you can depend on it (from the java build path) just like another java project. But since it's a plugin, that probably won't help them run.

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