views:

28

answers:

1

We are developing an Eclipse plugin that is split into several Eclipse Projects. We want to export some of the classes that are defined in these external projects (via Export-Package in MANIFEST.MF). The problem is that Eclipse gives an error "Package xxx does not exist in this plug-in".

To give an example, let's assume that the plug-in is project P1 and this one uses some classes defined in a separate Eclipse project P2. We want to bundle P2 together with P1 and export some of the classes of P2 via the MANIFEST.MF of P1.

This works if I generate a jar file (P2.jar) and add this in the build path of P1, however it does not work if I simply add P2 as a dependency of P1.

Any suggestions what is the reason of the "Package xxx does not exist in this plug-in"?

Any suggestions how to get rid of it?

A: 

Adding the project P2 as dependency of P2 simply add the build classes of P2 (assuming P2 is a Java project) to the classpath of P1. This will allow P1 to compile but will result in wrong behavior at run-time.

Because your project P1 is a plugin project all its dependencies must be added ever through the dependencies tab of the manifest editor or through a jar file included as you mentioned.

So the only solution is to transform P2 project into plugin project and then let your P1 plugin depends on it. This kind of plugin only exporting code but not contributing anything to the ide are often referenced as library plugins. More and more java libraries are now delivered also in this way to let clients use them in Eclipse context (for example log4j).

Manuel Selva
Thanks for the answer. However, I don't understand why will adding P2 classes to the classes of P1 will result in the wrong behavior at runtime. Currently in our build process (we use MAVEN), P2 is a MAVEN dependency of P1. What MAVEN does is it produces a JAR of P2 and bundles this together with the classes of P1. This works well at runtime, however it is terribly difficult to debug P1 in Eclipse (you need to do a mvn deploy after each edit in P2).
Oppy
If P2 classes are bundled in a Jar file that is added to P1 classpath through the Manifest editor runtime's tab there is no problem. The problem is about adding manually the P2 project in P1 dependencies using right click on the project and then Properties -> Java Build Path -> Project.Can you check the Manifest Runtime tab of P1 and check that p2.jar is present ?
Manuel Selva
The MANIFEST I generated manually and it contains p2.jar in the Bundle-ClassPath
Oppy
As we're using m2eclipse (MAVEN plugin for eclipse), and P2 is a maven dependency of P1, I have the P2 project in Properties -> Java Build Path -> Libraries. Here m2eclipse creates a special item, where it places all the project's maven dependencies. With this configuration, I get a "Package xxx does not exist in this plug-in" error. To solve this, I have to manually add P2.jar into Properties -> Java Build Path -> Libraries in order to get rid of this error.
Oppy
I am not aware about MAVEN. The thing I can confirm say is the following one: "in order for P1 to be able to see P2 classes, a p2.jar file must be added inside p1 and then included into P1 manifest runtime tab and also into p1 manifest build tab". I don't know if you have to do that or if MAVEN is able to do it for you.
Manuel Selva