I'm using BndTools (http://bndtools.org/) to develop an OSGI application. Everything is working fine but I have some things I would like to change while exporting my app.
I'm trying to achieve two things (I think they may be related):
aQute.launcher
) with a custom one (Or have it in .JAR
format)How can I get rid or change the default BndTools launcher (aQute.launcher) to a custom one?
The only thing I could find out on this topic is here: http://goo.gl/jYliih
Launchers are not build into bnd, the actual launching strategy is parameterized. A launcher is associated with a bnd or bndrun file by placing a JAR on the
-runpath
. A.JAR
should have a Launcher-Plugin header to be a launcher. If no launcher is found on the-runpath
then the built-inbiz.aQute.launcher
will be used.
The reason is that I need my app to accept command args and not interfere with the aQute launcher ones (Like all -run args). On the other hand I would like to get rid of the batch .bat/.sh
approach of launching the app and use a single .jar
file to launch the app.
Is that possible?
By default BndTools creates this file structure when it exports the app:
jar/
-> This is the OSGI jar bundles folder
aQute/
-> The default BndTools Launcher (Launcher.class inside)
META-INF/
-> Why is there a META-INF folder here? It's not a JAR
launcher.properties
-> Launcher properties
start.sh
--> Launches the Launcher.class from this batch files.
start.bat
/ Where is the benefit of this in comparison of a JAR?
Basically I would like to remove the aQute
, META-INF
and start.*
files and add a bin
folder for binary files.
This should be possible to achieve with a "Ant", "Maven" or "Gridle" script. But I can just create a "BndTools Project" or a "Gradle Project" with no BndTools support. I installed the "BndTools Gradle plugin" but I couldn't find any useful documentation on this topic anywhere.
Hope somebody can help me out or point me to the right direction with this. Greetings.
(This question was also asked on the bndtools group list)
I am a bit confused since the wishes you have seem to be granted. You can export a bndrun file to a single executable JAR. In a bndtools program you can access the command line arguments by getting an Object service and then the “launcher.arguments” service property. This is the original String[] given to the main method of the launcher.
@Reference(target=“(launcher.arguments=*)”)
void setArgs( Map<String,Object> args ) {
… = (String[]) args.get( “launcher.arguments”;
}
The exported JAR is an executable JAR. The can easily be converted by JPM to a local executable.
jpm install -n mycode mycode.jar
You can install jpm from https://github.com/bndtools/jpmcli
Robert: Thanks Peter, the launcher argument code snippet is just what I needed.
About the folder structure:
I need my bundles to be updateable. If I embed all the bundles inside of the .Jar then it won't be possible to update them. I just need to package the Launcher while having the bundles outside.
BndTools has two export options. 1 where you can embed the whole launcher and all the bundles inside of one JAR. Or option 2 is to have the bundles inside of the lib directory and start them via shell scripts (start.bat, start.sh). I'm seeking for a shell-script less solution.
Peter: Even though the bundles are inside, you can still update them as long as you do not clear the Framework’s storage area. You can easily include File Install for example and load bundles from a directory or use another management agent, Apache Ace.
From my perspective the current JAR export (I actually quite dislike the directory export, it is messy) is as good as it gets. It has a very nice release model, just one file that is easy to version and update. With JPM, you can install it on any system.
So if you want something else you will have to create your own exporter …