Joshua Gleitze
Joshua Gleitze

Reputation: 927

Add Classpath Container to Eclipse Plugin’s Runtime

We use a classpath container (provided by Buildship) to manage non-plugin dependencies in our Eclipse Plugin Project:

enter image description here

This works very well and the projects compile as expected.

However, if we launch our project using an “Eclipse Application” run configuration, we get errors like

java.lang.NoClassDefFoundError: org/apache/commons/collections4/multiset/HashMultiSet

as soon as our plugin is activated. So obviously, Eclipse uses the classpath container to compile the project, but does not add it at runtime.

I’ve searched the internet quite a while to find a solution for this, buy I didn’t:

How do I tell Eclipse to add the classpath container to the project’s runtime classpath?

I did not find any option to do this. I know I could add the dependencies’ jars to the classpath in MANIFEST.MF, but I’m not willing to do so. This completely contradicts the idea of classpath containers. Instead, I want Eclipse to automatically add all jars from the classpath container to the runtime classpath.

Upvotes: 2

Views: 1782

Answers (2)

Joshua Gleitze
Joshua Gleitze

Reputation: 927

I found a solution that works for us:

Development

During development, we load the dependency jars by adding them to the bootclasspath. For “Eclipse Application” run configurations, we can add the following to the configuration’s JVM arguments:

 -Xbootclasspath/a:"${project_classpath:Project1}:${project_classpath:Project2}"

This is convenient, because it will add all classpath containsers to the runtime. So we can have true dependency management through gradle and classpath containers.

Production

For production, we’ll wrap our dependencies as Osgi bundles and automatically add them to MANIFEST.MF. We’re using gradle to build our project, so this shouldn’t be a problem.

Upvotes: 0

greg-449
greg-449

Reputation: 111217

You can't do this, everything the plug-in depends on must be listed in the MANIFEST.MF in the 'Require-Bundle', or 'Import-Package' or 'Bundle-Classpath'.

When you export a plugin there is no information about the project classpath included in the plugin.

Upvotes: 1

Related Questions