OSGi bundles dependency management in Eclipse - eclipse

I have an OSGi bundle which is in Eclipse IDE represented as Eclipse Plug-in Project. The only way I found to satisfy the dependencies of this plug-in/bundle is to
1) import all dependencies (.jar files) through File > Import... > Plug-ins and Fragments wizard
2) and then declare the imported dependencies in MANIFEST.MF
Yes, this solution works, but on the other hand after I commit the changes to our repository all my team mates also have to manually import dependencies to Eclipse to fix the compilation errors.
QUESTION:
Is there a solution which does not require such irritating steps? I just want to pull the changes from repository and continue my work without need to fix the dependecies in MANIFEST.MF again and again...
P.S.: To retrieve dependencies we use Apache Ivy.

You need to set up a target platform in Eclipse. I find the easiest way is to put all the dependencies in a folder, and save the target platform as a .target file which I check into source control. Then the only steps my colleagues need to do is retrieve the dependencies and configure Eclipse to use the shared target definition. If we add new dependencies to the definition Eclipse will automatically pick up the changes with a restart or target platform refresh.
The Eclipse documentation should get you started: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.pde.doc.user/concepts/target.htm

If you develop server based applications then it is much better to let maven or Ivy manage the dependencies and use the maven bundle plugin to generate the Manifest. So you can avoid the Eclipse OSGi mode and the target platform. See http://www.liquid-reality.de/x/DIBZ for a tutorial how to develop OSGi bundles using maven and deploy on Apache Karaf. For Ivy you may have to use a slightly different build but the basics should be the same.

Related

How to use jars in an Eclipse library for eclipse annotation processor?

I want to use the annotation processor that comes with the Ollie library in Eclipse.
Hopefully, the annotation processor is available in the maven repository.
Using Ivy with the Ivyde Eclipse plugin, you can define a separate Eclipse jar library that has only the compiler binaries easily by creating a separate ivy file (named here ivy-compile.xml).
Which is convenient in case the annotation processing tool has many dependencies.
The issue is that Eclipse doesn't let me pick the jar from an Eclipse library. Only from a real folder.
Is there a way to tell eclipse to use the jars in the ivy-compile.xml container?
This thread might help you :
You'll need to add the IVY runtime to the build path of the project. This can be done via Project Properties->Java Build Path under the Libraries tab, select Add Library then select IvyDE Managed Dependencies.
Once that's done, an Ivy resolve will add all the jars specified in ivy.xml to the project's build path.

Using maven generated sources in Eclipse

I have an application made up of a number of maven projects. I work on it in Eclipse. Some of the projects use Maven plugins to generate stub classes for web services etc.
When i import the projects into a new workspace I have to issue a maven generate sources command followed by attach source folders to build path on each project. The application i work on has more than 5-6 projects which require these steps.
Is there a plugin I can install in Eclipse to pick up the generated sources, or even one that generates the sources and updates the build path to save the manual steps?
I'm pretty sure the m2e plugin takes care of this automatically. m2e is included in the primary Java and Java EE packages of recent Eclipse versions, so you probably already have it. If you right-click on your project, and there is a Maven submenu, then the project is already managed by m2e. Otherwise, right-click and choose Configure > Convert to Maven project.
Well, it depends on exact maven plugin you are using.
generate sources
Before I considered that m2e connector would be needed for any non common plugin, like generator. But I came recently on some plugins (1), that do it without special m2e connector.
attach source folders to build path
For this part check build-helper-maven-plugin and answer to M2E and having maven generated source folders as eclipse source folders

Eclipse RCP - how do all the jars / bundles interact?

I am developing an Eclipse RCP application and currently my head's a mess. I simply don't understand how the plug-ins and the other normal projects interact with one another, nor do I see how they interact with org.eclipse.* projects either.
So I have the Java Build Path that states which JDK I'm using, and also any external jars I might be needing, and the Target Platform that states on what plug-ins will the RCP application base upon, right?
Now I keep seeing all these required jars:
Plug-In Dependencies
Required bundles in manifest.mf file (listed in Eclipse in the Dependencies tab)
build properties' additional bundles
So where exactly do these jars need to be? In the Target Platform? or in the Build Path?
Does anyone know a good guide to describe this?
Any help / opinions /suggestions are appreciated.
EDIT: I've tried it out, and it seems that when there is a required bundle, it is resolved by adding it to the Target Platform...
The target platform is where you list the complete set of plugins that your RCP depends on, this might be one of the Eclipse downloads or it could be something else entirely.
The Required Plug-ins tab of the manifest.mf lists the plugins that your plugin uses directly. Eclipse will use this to maintain the class path for the plugin and will manage the Java Build Path automatically.
The Plug-in Dependencies list shows your plugin dependencies plus the indirect dependencies.
I have never had to use the additional.bundles in the build.properties so I am not sure why it would be used, none of the plugins in my RCPs use it.
Also on the dependencies tab is Imported Packages. This specifies packages to import without specifying a plugin, see Why do we need `Imported Packages` when we have `Required Plug-ins` in eclipse plugin dependencies?

Eclipse and Ant integration

Is there a way for my eclipse project to inherit the build classpath from existing Ant build.xml files? It would be nice if I didn't have to keep the eclipse project and the ant build in sync!
Off-hand, I'd say no, but see here http://www.ant4eclipse.org/node/6 for an attempt at doing the opposite (keeping the Ant build path in sync with Eclipse). Maybe that's of some use?
Another option would be is for both ant and eclipse to point to a common file specifying dependencies, independent from both ant and eclipse.
You can do this with ivy (http://ant.apache.org/ivy/), which has both tasks for ant and a eclipse ide plugin. ivy also solves the third-party library dependency management problem (you create a central repository of all third-party dependencies in your company which are pulled down as needed, rather than keeping .jar files with each project).
It takes a little time to create the initial ivy repository by copying libraries from maven, but is well worth it longer-term.

Eclipse+Maven compile problem

currently, I am developing web-apps using Eclipse.
The build is done using Maven.
The problem is that during compile time Eclipse is showing a lot of errors since there are a lot of missing jars. The final result is OK since the Maven is responsible for fetching these jars.
How can make the eclipse not fail the compilation?
I know I can just add the missing jars to the project classpath, but that's not what I'm looking for because I have a lot of projects, and the .classpath file of each project is a file common to all developers, so I would rather not to change it.
My question is therefor, is there a way to add a common classpath to all Eclipse projects without changing each project's classpath?
I use m2eclipse. It adds a classpath container to the .classpath file. This container is populated with the Maven dependencies by a Maven builder (added to the .project when the Maven nature is enabled) which processes the POM and downloads any artifacts (and sources if needed).
To enable the Maven nature (assuming the plugin is installed), right-click on a project and select Enable Dependency Management.
By default m2eclipse uses an embedded version of Maven to do its processing. This typically means a separate local repository and duplicate files on the box. You can configure it to use your standard Maven installation in Window->Preferences->Maven->Installations. Then adding the path to your Maven installation (normally the same as M2_HOME).
There is another Maven plugin for Eclipse called IAM (formerly called Q4E). IAM is an Eclipse integration project and has some promising features - it's worth keeping an eye on.
There is a comparison of the Eclipse Maven integrations, alongside the maven-eclipse-plugin (a goal that generates the Eclipse metadata files from the POM contents). I personally find the maven-eclipse-plugin more trouble than it's worth but it may suit your purposes and it is handy for generating the initial metadata if you have none checked into the SCM.
Check out the m2eclipse plugin. It will read each project's POM and automatically fetch and add all dependencies to the classpath.