I have an eclipse .target file which I want to cache locally. I want to provide the users of my project with a means to execute a maven project to download the content into a P2 or archived P2 repository structure on the local disk.
Note: I am aware of the wrappers for the P2 director and other extra tools. This question is about using a target file as the input to that functionality.
I'd like to retrieve the content of an update site. I tried the general way ("Help -> Install New Software"), but unfortunately I can't download the content because of conflicting dependencies. Is it possible to download the content of that repository manually, so that I can work with the plugins myself?
You can create a local copy of a remote p2 repository with the p2 mirroring tool. You can call that tool
as Eclipse application,
as Ant task, or
as Maven goal.
To create a local mirror of an Eclipse update site you may want to try the B3 Aggregator, https://www.eclipse.org/b3/.
It comes with an Eclipse editor for specifying the features/bundles to mirror from which update sites.
Background
My Eclipse RCP application is built using Tycho. It consists of multiple components (in the form of OSGi bundles/Eclipse plug-ins). One of these component contains the product file and materializes the product.
There is a reactor POM at the application root, which builds all components in order, but I also want to build other components independently (using mvn deploy) .
Building such a single component works as follows:
Retrieve the latest versions of all the component's dependencies from our company (p2) repository.
Build the component.
Deploy the component to our company repository to be used as a dependency for other components itself.
Note: Our repository is a normal maven2 repository hosted on a Nexus, whose RCP artifacts are automatically mapped to a p2 repository format as well. This way, Tycho can use the p2 repository format to find dependencies, while the standard Maven deployment can be used. This works fine.
Note: My parent POM makes sure that we look for dependencies at the p2 repository URL. The deployment URL is the default maven2 format location of the repository. This works fine.
Problem
When building such a single component through the command-line (mvn deploy), Maven looks for intra-project dependencies in the p2 repository and they are correctly resolved (i.e. latest version is automatically downloaded and used in build).
However, when developing in Eclipse, the IDE cannot resolve them. The manifest files gives an error at each of my intra-project dependencies that they cannot be resolved.
Question
My question is: How can I make the Eclipse IDE look for dependencies (and new versions of dependencies) in either:
My local p2 repository (~/.m2/repository/p2/osgi/bundles)
My company p2 repository (nexus.mycompany.com/myproduct-snapshots/.meta/p2)
Ideally, it would look for them every time and fetch the latest version if a newer version is available.
If it does not use the p2 repository URLs in the POM, how should I configure Eclipse?
Example
Consider an eclipse plug-in com.mycompany.myproduct.fancy, which depends on another eclipse plug-in com.mycompany.myproduct.core.
Both also have a POM (configured for Tycho use), which (through their parent POM) have my Nexus repositories configured correctly: maven2 repository URL for deployment and p2 repository URL to look for dependencies.
First I deploy the core plug-in to my maven repository (using the default mvn deploy). The Nexus repository will provide this deployed plug-in in both maven and p2 format.
When I build the fancy component through the command line (using mvn install), the (earlier deployed) core component is found and downloaded automatically.
project/com.mycompany.myproduct.fancy$ mvn clean install
<searches in p2 repository, download core>
<builds fancy>
<SUCCESS>
When I open a new Eclipse workspace and open the fancy component, its Manifest (which contains its dependencies) gives the following error:
Bundle 'com.mycompany.myproduct.core' cannot be resolved.
My question is: how can I develop the fancy component in the Eclipse IDE without the need to open core as project in Eclipse.
Speculation
This is some speculation from my side. Please correct me if I'm wrong and any other solution to the actual problem is also welcome!
I know the m2e plug-in of the Eclipse IDE currently maps Maven POMs to Eclipse concepts (using m2e connectors). I have installed the dedicated Tycho connectors. For example, the mvn compile step is actually performed by the Eclipse JDT compiler.
I also know that when a complete Tycho product is started in Eclipse, it is run in the Eclipse PDE environment. For example, I need to a specify a target platform in my Run configuration.
I know I can open all components in my Eclipse workspace. This would solve the problem, but is not feasible as I have many components and this would break independent component development.
I assume the Eclipse m2e mapping and/or the PDE build environment is not smart enough to fetch (latest) dependencies automatically at build time. Please correct me if I'm wrong. :)
Therefore, I assume I need to specify the target platform at build time too. I have taken a look at Window > Preferences > Plug-in Development > Target Platform. I can add our p2 repository to the Target Platform, which solves the problem. However this gives many problems:
I need a feature containing all components for this to work. Only features can be added.
Every time I deploy a new build of a single component, I would have to rebuild the complete feature (to create a new feature version on our p2 repository).
Every time I update a component and build the feature, I would have to manually change the Target Platform.
If the above is all correct, I speculate I need an m2e connector (or a different one from the current one) that actually checks the p2 repositories specified in the POM when resolving the OSGi dependencies and automatically adds those to the target platform.
As indicated by Nick Wilson, you will need to install the m2e Tycho Configurator, which basically "links up" Eclipse and Tycho (i.e., makes Tycho available in Eclipse).
You should've been pointed towards it after having installed m2e, but you can also install it manually:
Go to Window > Preferences > Maven > Discovery.
Click the "Open Catalog" button. This will open the "m2e Marketplace" window.
Search for "tycho", this should give you the "Tycho Configurator" as sole search result.
Click "Finish", you're done.
I've had this issue as well, and it isn't simple to find the solution, so I hope this helps!
The "most automated" way to configure your target platform in Eclipse is to use a target file. That file can be checked in with your sources, so every developer only needs to open the file and click on "Set as Target Platform" to activate it. AFAIK there is no m2e connector or Eclipse plug-in which does that automatically.
Given your development process, setting up this target file is a little more tricky. Since you don't have a feature which contains the latest version of all your bundles, you need to include the bundles directly in the target file. This is not possible via the rich editor, but can be done with a text editor:
Create a target definition file, add your p2 repository, and select any feature from that p2 repository. Save the file.
Open the target file in a text editor, remove the <unit> entry for the feature you added.
Instead, add an entry for each of your bundles:
<unit id="a.bundle.symbolic.name" version="0.0.0"/>
This target file then contains the latest version of each of the listed bundles. To see the content, open the file with the "Target Editor" again and switch to the "Content" tab. This file can now be used by all developers.
Note: When a new version of one of the bundles is deployed to Nexus, the developers will only see that new version if they open the target file and choose "Set as Target Platform" again.
I'm trying to implement the p2 update mechanism into an RCP application that contains DLLs (integrated via JNI). The whole RCP application (including these DLLs) has to be kept up to date.
Currently the PDE build is not aware of the DLLs - make/gcc generates and copies them into the delivery in the end.
How to make p2 aware of the DLLs? They have to be added to the p2 repository and p2 within the RCP application has to update them, when newer versions are available.
Include the DLLs in your plugin.
After you have gnerated them, copy them into a folder in your plugin project. Then add the folder containing the DLLs to the Binary Build section in your plugin.xml editor. You can make the plugin aware of the DLLS using the Bundle-NativeCode: entry in the Mainfest.mf of the plugin. This way the DLLs are included inside your plugin's jar and are therefore automatically included in your p2 repository.
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?
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).