Launching OSGi from IDEA - scala

I develop scala application using IntelliJ IDEA. I'd like my application modules to be OSGi bundles.
In Eclipse it is possible to create a project which is both scala project and plug-in project. Eclipse also supports launching of Equinox platform and provides great configuration tool of which bundles to start and how. But I can't use Eclipse because of poor and slow scala plugin, so I need to use IntelliJ IDEA.
In IDEA I tried Osmorc for running OSGi but this solution is very immature and doesn't work well. What are the other ways of launching and configuring an OSGi application from IDEA?

Not an exact answer, but one possibility would be to:
set up a scala project with sbt and Intellij
use bnd4sbt (It enables you to create OSGi bundles for your SBT projects)
use scalamodules (a domain specific language for OSGi development)
(All thanks to the work of WeigleWilczek, including Heiko Seeberger who contributes here)

All the OSGi frameworks can be launched as standard Java processes. For example to launch Felix:
java -jar path/to/felix.jar
To launch Equinox:
java -jar path/to/org.eclipse.osgi_version.jar
And so on.
Unfortunately the initial configuration differs substantially between framework implementations. For Felix you need a config.properties file, which is typically in the conf directory of the Felix installation directory (or you can set the felix.config.properties system property to point it elsewhere).

I'm using PAX runner from inside Intellij IDEA to provision (deploy) OSGI bundles to Apache Felix and run the framework, but this is very annoying: I have to run "mvn install" first, then stop the running pax provisioning session, then restart it - for every change I make in the bundle. There got to be be a better way...

Related

Hot code deployment during development with embedded Apache Felix and Eclipse?

I am trying to embed Felix in an application of ours to handle plugins. Everything is working fine, however, development and debugging is very cumbersome.
Is there a solution where I can tell Felix to automatically reload a plugin bundle or its classes when I recompile a plugin in Eclipse?
I cannot use any OSGi specific launchers because Felix is embedded in our application
Felix' fileinstall supports directories, but expects a specific structure, which is incompatible with the layout of the Eclipse project.
Any help or pointers to a solution would be greatly appreciated.
You could take a look at Bndtools and the remote launcher. You only need to install a remote agent in your framework and then Bndtools can update any bundle that has changed in the workspace.
This is explained in remote launching. In OSGi enRoute you find an IoT tutorial that uses this model as well as a Karaf App Note.

How to debug OSGi applications?

I really need to debug my code by the use of breakpoints, however this seems a complex undertaking with an OSGi container.
I have Eclipse and Felix (both the latest). My project is a raw OSGi project, I am not using PDE, just maven bundle plugin to generate the bundles and then copy them to the /bundle folder in felix, then I perform java -jar bin/felix.jar and the project runs. So no fuss here.
However I cannot debug the application that way. I've tried to read the docs (http://felix.apache.org/documentation/development/integrating-felix-with-eclipse.html) but they are outdated/broken and cant make them work...
How can I debug this? Will I have to avoid using OSGi just because debug is not supported...?
Thanks!
Have you considered using an IDE tool like bndtools to do the debugging? You can create a repository from your folder of bundles and run them using a bndrun file. This gives you a debug environment in Eclipse which sounds to be what you want. The bndtools website is here.
Bndtools also does a lot more, but it sounds as if you're happy with your existing Maven build. The tutorial runs through setting up a basic workspace, but the main thing you'll be interested in is Running a framework
Start felix with the following parameters to enable remote debugging.
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 -jar bin/felix.jar
After you can connect via Eclipse Remote Debugging to your Felix Container.
Run
Debug Configurations
Remote Java Application
Choose as project the project/sources you want to debug
Configure port to 1044
Trigger debugger by clicking on debug

Compiling and running an OSGI application in Eclipse

The base of our enterprise application is OSGI and we have several Java projects that are logically OSGI bundles. We use Maven to compile the application using the Maven Bundle plugin. But this process is time consuming and makes it impossible to debug the application. We also use the Runner and Pax(:provison) plugins to run the application. If we could rely on the Auto build function of Eclipse and also debug the application it would make our lives so much easier. Is there a way to configure Eclipse to be able to compile (and may be run) an OSGI-based application?
I'm not entirely sure if I understand you, but here goes.
Well, running/debugging OSGi applications in Eclipse is really easy, as long as your bundles reside in PDE aware projects or at least are on your target platform.
Do you have the source of all your bundles? Debugging without source isn't all that useful. If you do, can you just import all the source of your bundles into your Eclipse workspace?
Otherwise you can create a target platform, add all your bundles to that. (as a first attempt, I'd say dump all your bundles in a directory and point the target platform there)
Either way, then you should be able to Run (or debug)-> OSGi framework -> New -> Pick your bundles -> Start
You can both pick bundles from or target platform and from your workspace.
For building, you can use Eclipse Plugin Development Environment (PDE). Despite its name, it isn't specific to building Eclipse plugins and can be used for working on pure OSGi bundles. Eclipse plugins are OSGi bundles with some extras.
Cannot help you with the running or debugging part, although I do know that some enterprise-oriented OSGi platforms provide extensions to PDE.
If you're already using the maven bundle plugin, you may find that PDE's manifest-first approach isn't a good fit with your existing code-first build (I assume at the end you want both an IDE build for development and debugging, and a command-line build for continuous integration and automated testing).
You have two choices. As others have suggested, you can use Eclipse's integrated PDE, and use Tycho for your maven build. Tycho uses the same data used by PDE, so you don't have to write things down more than once. Alternatively, you can stick with the maven bundle plugin and use bndtools within Eclipse. Like the bundle plugin, bndtools is code-first, so you won't need to worry about maintaining manifests. However, you may find there isn't quite as big a set of features in bndtools as in PDE, and I'd suggest still checking your manifests by hand to make sure you understand what's being generated. Whether you prefer manifest-first or code-first is a bit of a heated philosophical debate.
Look at bndtools. bndtools is using the same bnd that is underlying the maven bundle plugin. You can even use bndtools together with m2e. bndtools is available from the Eclipse market place.

Eclipse configuration to support dual Equinox/Felix environments

What are some configuration changes to make Eclipse PDE best support working with both Equinox and Felix?
Here's an example problem I'm currently having. I can run my application ok via the Eclipse OSGi Framework launcher. Similarly, there are no compilation problems in PDE. However, when running in Felix I will get NoClassDefFoundErrors:
java.lang.NoClassDefFoundError: org/w3c/dom/DOMException
My understanding is it's my Eclipse setup that is at fault here; org.w3c.dom is not a 'default' OSGi package and shouldn't be loaded when I run it in Eclipse. Similarly, the import in my code for org.w3c.dom.DOMException should be an error.
I know how to fix this for Felix: declare an Import-Package. But that's not my question. My question is how to force Eclipse PDE to take on a closer configuration to Felix... basically to make it stricter in loading packages?
I think Equinox does behave like Felix, if you run it stand alone. It's more of an Eclipse legacy thing than an Equinox thing, as stated on osgi.org.
As far as I know, there isn't any way to override the boot delegation from Eclipse, but I'd love to be proven wrong, as I've faced this problem often.
If you are developing a server application I recommend to not use the PDE at all. I am using maven and the maven bundle plugin to develop my bundles. Then I deploy on Apache karaf. Debugging also is quite simple by using the karaf dev:watch command and remote debugging. I never really missed the PDE features and they never worked well with my maven build.
This sounds like that launcher is setting bootdelegation to legacy mode. See the following page on the OSGi Wiki: http://wiki.osgi.org/wiki/Why_does_Eclipse_find_javax.swing_but_not_Felix%3F

What IDE setup and workflow is used for OSGi development?

I made quite a few easy OSGi test projects in Eclipse RCP. My typical workflow would always be:
Make 3 different projects: APIproject, Clientproject and Serverproject
Edit the MANIFEST.MF of APIproject to export the api package
Edit the MANIFEST.MF file of Clientproject and Serverproject to add the required API package
Choose "Run as..." > "Plugin Framework"
OSGi console starts in eclipse and everything seems to work
I also tried wiring things by using Declarative Services, which worked well like this too.
Now recently I wanted to try out iPOJO. The problem is that I get the feeling that I've been doing my OSGi development the wrong way.
Can it be that I should instead make 1 project en make it work like no OSGi is involved. And then afterwards, just export each package to its own bundle by means of (for instance) the BNDL tool? Should development be done in a normal Eclipse (java, not RCP) or any other java IDE for that matter?
So that's why I have these questions:
What IDE setup is normally used to develop OSGi with iPOJO?
And what is the normal workflow to be used when developing OSGi projects (maybe with iPOJO)?
Normally when I develop OSGi bundles (not Eclipse RCP bundles) I use the following tools:
Maven 2 as the build system.
Apache Felix maven-bundle-plugin to generate MANIFEST.MF automatically.
Pax Exam to create integration tests that run inside an OSGi container.
Pax Runner to execute my bundles in any OSGi framework (equinox, felix, etc.).
IntelliJ (or sometimes Eclipse) as a standard IDE without any OSGi extras.
I have not yet developed any Eclipse RPC bundles, but there's a new tool for Maven 6 Eclipse RPC build integration called Tycho (http://tycho.sonatype.org).