nozebacle
nozebacle

Reputation: 406

Can't access class in Eclipse plugin from a Java Project

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.

Upvotes: 0

Views: 1266

Answers (1)

Paul Webster
Paul Webster

Reputation: 10654

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.

Upvotes: 1

Related Questions