Creating an executable/fat JAR for a java 8 Equinox(org.eclipse.osgi) project

Hi everyone,

I’m trying to create a single executable JAR for a legacy OSGi desktop application.

Context

Application: OSGi/Equinox

Runtime: Java 8

I cannot use Bndtools UI in Eclipse. I think it doesn’t support for java 8.

I have biz.aQute.bnd-6.4.1.jar avaible.

What I did

  1. I created a config.bndrun based on my existing Equinox config.ini configuration.

  2. I collected all bundles that my application uses (from my runtime/plugins), and put them into a “plugins/“ folder keeping their original names-versions.

  3. I can generate bndFatJar.jar using this command:

    java -jar ./biz.aQute.bnd-6.4.1.jar package -o bndFatJar.jar config.bndrun

    The JAR is created successfully and its contents look correct when I inspect it.

Problem

When I try to run it using:

java -jar bndFatJar.jar

a console window opens but nothing seems to happen ( no Output, no framework logs, no UI, no error). The application does not start.

Questions

  1. For a java 8 + OSGi based application, what is the recommended approach to create a runnable artifact?
  2. Are there any “must-have” run bundles / properties for OSGi when launching via bnd (e.g start levels,etc.)

Any step by step guidance would be really appreciated. Thanks!

Not that I have tried it myself, but maybe you could try setting system property -Dlaunch.trace=true when you start via java -jar...

Is see in the code there is logging in EmbeddedLauncher if this is set:

Is your Desktop Application an Eclipse RCP?

It is based on Equinox/OSGi, but not using the Eclipse RCP UI framework. It is a custom desktop application built on top of Equinox. Is there any other way for creating an executable jar for our project. We can’t use bnt tools on Eclipse for our project, right?

As long as you don’t mind using Java 17 or higher in your build process, you can use the latest Bnd. So yes, you can use Eclipse.

You will need to make sure version 6.4.1 of the launcher is in your app, and set -runee appropriately, so that it can run in Java 8.

So, even though my project is Java8, I can still install the latest BNDTools file and get the FAT JAR, right? What steps should I follow to do this? How do I configure Launcher 6.4.1? Should I use the existing launcher JAR file instead? Can you explain it step-by-step? I’m new to this :slight_smile:

Welcome @usenol
I have a example repo containing mininal eclipse rcp applications inside a bnd workspace.
You can have a look at e.g. example.bnd.rcp/example.rcp.app.ui at main · klibio/example.bnd.rcp · GitHub

Regarding your question on Java 8.
Yes. You can use the latest and greated bndtool version and still produce Java8 compatible bundles and executables.
This repo and project is creating Java 8 compatible bundles.

https://github.com/klibio/mvn.deploy.bnd/tree/main/mvn.deploy.bnd

Mind the usage of the javac.*settings inside the bnd.bnd file.
The mvn-deploy-bnd.bndrunin the same repo is used for creating the executable jar for Java 8.