Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice to add a maven dependency to an Eclipse RCP Plugin

I want to add some GitHub projects as dependencies to my Eclipse RCP Plugin. The GitHub projects are oshi and leshan.

Both GitHub projects provide maven builds over maven central which i could use.

But as i understand so far i cant use these builds directly in an Eclipse RCP Plugin because it requires OSGI-Bundles - in contrast to an "classic" Eclipse Java project.

So far i found three ways of dealing with this problem:

  • let Eclipse convert the JARs to an OSGI-Bundle and add them to a Plugin which i can make a dependency on (described here https://stackoverflow.com/a/3594698/12029492)

  • look if the GitHub projects are available on Eclipse Orbit and add the p2 Repository to my Target Platform. (described here https://stackoverflow.com/a/56854979/12029492) Sadly on the Orbit site is only the oshi project in an older version than it is on GitHub.

  • create my own p2 repository with p2-maven-plugin and add it to my Target Platform.

I also looked into Tycho but as far as i understand you can only add a p2 repository as a dependency in Tycho, which leads again to the problem of creating one.

Is there another/better way of dealing with Non-OSGI-Bundle Maven builds in an Eclipse RCP Plugin?

EDIT: i found for me the best way to use gradle (a gradle plugin bnd-platform), to automatically resolve the dependencies using maven central and create a local p2 repository, described in Option 1 here https://stackoverflow.com/a/29509794/12029492

like image 549
J0n8s Avatar asked Sep 06 '19 10:09

J0n8s


People also ask

How to update Eclipse project with Maven dependencies?

If not add a pom.xml or read this postto know about creating an Eclipse project using Maven) and run following command to update the eclipse project. mvn eclipse:eclipse Alternatively you can also use an Eclipse plugin to handle Maven dependencies. An example for such a plugin is the m2eclipse plugin.

How to integrate Maven with Eclipse?

Verify if the Maven plugin is already provided in the Eclipse from Windows =>Preferences, Maven should be present there. All the current Eclipse versions have the Maven plugins by default and if it is not there, we can get it from here. #3) Now to make Maven and Eclipse work in conjunction, import the Maven project from the File.

What is the best Maven plug-in for Java EE IDE?

The most popular Maven plug-in for Eclipse Java EE IDE is called Maven Integration for WTP (m2e-wtp). Installing this plug-in is easy and would take only around 5-10 minutes.

What is the scope of a Maven dependency?

Maven dependency that has a scope of the test is not required for the building and running of the project. They are essentially used for compiling and running the unit test cases. The below code snippet shows a test scope dependency.


1 Answers

Recently the Eclipse Maven (M2E) implemented tight integration of Java libraries from Maven central into the target platform. With this, you can easily add Java libraries to your target platform and they can be converted (if necessary) on the fly to OSGi bundles including their dependencies.

See https://www.vogella.com/tutorials/EclipseJarToPlugin/article.html for how to using Java libraries (from Maven Central) for OSGi, Eclipse Plug-in and Eclipse RCP development.

This extension is also supported with the latest Maven Tycho version for command line builds, see https://www.vogella.com/tutorials/EclipseTycho/article.html

like image 137
vogella Avatar answered Oct 18 '22 19:10

vogella