Home » Java » Enterprise Java » Adding JAR Dependencies to an Eclipse Plugin Maven Tycho Build

About Arieh Bibliowicz

Arieh Bibliowicz
Arieh is a longtime programmer with more than 10 years of experience in enterprise grade software projects. He has worked as server-size programmer, team leader and system architect in a mission-critical high-availability systems. Arieh is currently a Program Manager (PM) in the Microsoft ILDC R&D center for the Azure Active Directory Application Proxy, and also a PhD student at the Technion where he is developing a Visual Programming Language based on the graphical language of the Object-Process Methodology, using Java and the Eclipse platform.

Adding JAR Dependencies to an Eclipse Plugin Maven Tycho Build

Something that is constantly bothering me when developing the OPP project is the use of hard-coded Java library dependencies. I manually downloaded the jars for the libraries I use, copied them to a directory in the plugin that required them, and the added them to the MANIFEST.MF file.

You are probably asking why am I doing this. Well, Eclipse plugins (or more correctly OSGi projects) are built in Maven using a plugin called “Tycho”. This build process is different from the standard java Maven build process, specifically in how it handles dependencies.

OSGi dependencies are defined in a MANIFEST.MF file and not defined in POM of the project. When Maven is executed, it looks at the MANIFEST.MF file, extracts the dependencies, and then tries to download them from one of the repositories defined in the POM, which, as expected, are defined differently than Maven repositories.

We love standards. That is why we need at least two of them :-(.

So back to my problem: I have a number of simple Java dependencies that I am using in my projects. So searching the net I found the Apache Felix Maven Bundle Plugin (BND). After trying and trying again to get its configuration right, I gave up. Maybe you need a PhD to configure this, so I’ll come back again in a couple of months (hopefully :-)).

But hey, I’m a developer, and I should scratch my own itch, so why not develop a Maven plugin that does what I want? Yep, good idea! But after two weeks of work (by work I mean the only half hour available to me each day to work on this, excluding weekends) I found myself with a simple Maven plugin that is able to copy a file from here to there, but the learning curve is a steep.

And then I reinvented the wheel, because the solution was already posted in StackOverflow and I had read it a while ago, but disregarded it. Last week after learning some more Maven (because I was writing a plugin), I understood that I could create a new project (standard Java maven project) where the dependencies are downloaded and then copy the dependencies to my Eclipse plugin project. After a couple of minutes, Voila! It Works! You can find the results in the OPP repository. The Java only project is com.vainolo.phd.opp.java-dependencies which is required by the Maven module com.vainolo.phd.opp.utilities. Check how the POM files are written to see how this works. I also added the dependencies project as a child project of com.vainolo.phd.opp.releng so it gets built as part of the project.

There is also a simpler way to do this without another project, as described in this StackOverflow answer. Here the maven-dependency-plugin plugin is invoked directly in one of the initial phases of the build (i.e. validate), using plugin specific configuration to select the dependencies. Tried this but while it works for the direct dependency, it didn’t download transitive dependencies. This is probably a configuration things but at this stage I am not going to invest more time in this.

Maybe next year.

Happy coding!

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of