In Eclipse RCP project, you may need to create such kind of “Plug-in from Existing JAR Archives” projects, because you need to reuse non-OSGi jar, such as Google Guava, SLF4j and etc.
In our team, before we have to manually download the needed jar libs from website, then change build.properties, MANIFEST.MF. And of couse, these libraries should be uploaded to version control system (such as P4, Git), as others (as well as Jenkins) can sync to latest and build.
This approach has some defects:
- Too much manual work and hard to maintain the dependencis.
- 3rd party libs become more and more.
Here is a solution for that – using maven dependency:copy-dependencies to copy all needed libs.
tycho + maven
Tycho is a great maven plugin, which can help to do headless build for a Eclipse RCP project. It will analyze the dependencies in MANIFEST.MF and also in pom.xml. We can use the feature to define the 3rd party dependencies in pom.xml.
You can find more usefule information about tycho on Eclipse.com.
Define the needed libraries in pom.xml
Just as what a common maven project does, you can define the libraries you need in <dependencies> of pom.xml, such as,
Use maven-dependency-plugin:copy-dependencies to copy
Use the goal of maven-dependency-plugin:copy-dependencies to copy those jars to specific folder, such as,
The goal is defined at “initialize” phase.
With this pom.xml, you can do a manually build and retrieve the jars from maven repository. Then you need to put them into the bundle’s CLASSPATH and exported packages in MANIFEST.MF.
Using this way, you don’t need to worry about third party libraries in OSGi environment any more. All dependencies are defined in pom.xml. It’s very clean and clear. Of course, in real world, you need do more configuration in pom.xml (such as clean work) and an IDE environment integration.