How to build desktop applications with Apache Karaf/OSGi? - java

Well im into building OSGi application for a while, but i can't really find some tutorials which show the way to build Desktop Application ( in any languages ) with OSGi/Karaf.
I want to use karaf because it can then wrap Felix/Equinox. Most of Tutorials i found are about Enteprise Application(WEB). So is there any tutorials, which talk about building desktop application based on OSGi/Karaf?

Here is an example of a GUI application project that uses Apache karaf:
https://bitbucket.org/lorainelab/igb-fx
Using karaf to run a gui-based desktop application decreases development time. A developer makes a change to a bundle, builds the bundle, and then uses karaf shell commands to reload just that one bundle into the running application. There is no need to restart the entire application to view the effects of the new code. This is why were are using it.
We are using OSGi because we want greater modularity in the code base and because we want to support dynamically loaded "Apps" developed by 3rd party developers who write against our genome browser API.

Sorry the main intend right now for Karaf is to be used as a Server, though it still should be possible to start some guis on top. As your already familiar with building such bundles I'm sure you most probably could use just the minor version of Karaf and place your bundles in it. I have to admit I never done this before, so I'm not really sure about it.

First of all OSGI is a component framework, it also leverages a feature missing in Java since its inception - runtime versioning. If you really need it (OSGI), it doesn't depend wether you develop a WEB or desktop application. In general I would recommend you to take a look at this documentation:
http://fusesource.com/docs/esb/4.2/deploy_osgi/Build-ModifyMaven.html
In that link you'll find how to convert an existing Maven project to bundle, check further chapters - there's info how-to deploy jars in e.g. Karaf (Karaf is an OSGI container)
Hope, this helps

Related

How to get started with Java modules?

I'm reading about OSGi and JBoss modules. I understand the purpose of modules -- to avoid Jar hell and conflicting classes -- but I don't know where to start if I want to write a new application that uses them. Is there a kernel somewhere that I can start with, that then loads the other modules? I don't want to run Eclipse or Wildfly; I want to start fresh with my own app. Hello world for modules.
Edit: I'm using IntelliJ, and for several reasons I really don't want to switch to Eclipse. So I can't do much with answers that require I install Eclipse plugins.
OSGi would be the first choice. JBoss Modules is still much more an internal JBoss thing than a general purpose modularity solution.
To start with an OSGi application, take a look at Bndtools. This is an Eclipse plugin to make OSGi development easy. From there you can create a "run configuration" which is the definition of your application. From there you can also export the application to a single executable JAR to distribute your app.
This is a nice video to get you started.
Also, for more high level components (REST, databases, scheduling etc.) take a look at Amdatu.
Try starting with OSGi enRoute: http://enroute.osgi.org/. This is a project, still in development, to demonstrate using OSGi.

How do you break a large java application into components?

I am writing a java web application using spring, hibernate and mysql. The applications is getting larger so I want to break it into smaller parts e.g. smaller projects, components or which ever way possible. For example I have login and image uploading functionality, I don't want both of these to be in a single code base or project. I want to be able to use these separately almost like separate services independent of each other. Is there a way of doing this e.g. convert the image uploading functionality into a jar and then reference this jar in the actual project? How are the Enterprise projects split?
Hope it make makes sense and please advice if I am going the right direction as it is my first project? It would be nice if someone can point me to a mini example or recommend reading.
thanks in advance
Try with OSGi. If you are using Spring, then declarative services and possibly blueprint container in OSGi specs are what you need to leverage what you have done until now.
Try reading OSGi in Action by Richard S. Hall, Karl Pauls, Stuart McCulloch, and David Savage to get an insight in this technology.
OSGi is a modularazied approach for java software development that enforces loosely coupled services creation. Quoting from the OSGi alliance website:
OSGi technology is a set of specifications that defines a dynamic component system for Java. These specifications reduce software complexity by providing a modular architecture for large-scale distributed systems as well as small, embedded applications.
Hibernate supports OSGi as it can be seen here. As for the OSGi implementation, I would recommend Equinox, but many other valid OSGi implementations exist. Since your project is a web application, you could check also Virgo
Virgo from EclipseRT is a completely module-based Java application server that is designed to run enterprise Java applications and Spring-powered applications with a high degree of flexibility and reliability
and in particular,
supports vanilla WAR files, with all their dependencies in WEB-INF/lib, and Web Application Bundles, that import their dependencies via OSGi manifest metadata, via the reference implementation of the OSGi Web Container specification, based on embedded Apache Tomcat and configured using the standard Tomcat server.xml
I ended up using maven modules and maven dependency management capability. I created a separate maven project and kept adding maven modules as needed e.g. created a module for image uploading, one module for common libraries and so on.
Each of these modules are then packaged to jar files. I then import each one of these jar files using maven dependency to my main web project.
It seems to have worked great so far. Hope this is helpful for someone else, too.

Does OSGi-as-a-Service exist?

Are there any Java PaaS solutions out there that offer OSGi containers as a service?
Google App Engine --> has their own GAE server which is modified Jetty
CloudBees --> has their own RUN#Cloud container which is modified Tomcat
OpenShift --> uses JBoss/Wildfly
??? --> uses, say, Karaf or Equinox
If not a full-blown PaaS, just a clusterable/scalable OSGi host. Google turned up nothing, so I'm assuming there isn't anything like this. Thanks in advance!
(In contrast to the other answers:) No, there is no OSGi-as-a-Service in the cloud, yet.
I am currently writing my master thesis about porting an OSGi application on a PaaS, so I did my own researches about PaaS and OSGi. I did not find any satisfying solution based on OSGi in the cloud (however I did find other solutions ;). The problem is that OSGi is pretty unpopular and the cloud is notoriously trendy.
As the other questions mentioned, OSGi is a Java library. So you could set it up pretty much everywhere where Java is supported. But that would be more a IaaS solution as a PaaS solution (which you seem to look for, as you are asking for OSGi-as-a-service). You would need to setup a OSGi framework on your own and you would have no support for deploying bundles. Which degenerates this solution pretty much. So no, there is no special cloud offer for OSGi, despite there are many for Java.
However, there is a nice book called Modular Cloud Apps with OSGi from Paul Baker and Bert Ertman published by O’Reilly. The book describes their PaaS-like solution to use OSGi in the cloud. The basically setup a repository of OSGi bundles, where they stored all their stuff. Then they created a cloud image, which only contains an empty OSGi framework/server (just like Apache Karaf, but they wrote their own tool called Apache ACE for what reason ever...). They were able to boot those images and as soon as the machine was up, they just deployed the bundles from their repository to the instance (via a web interface).
There is also a video of their demo on youtube: https://www.youtube.com/watch?v=oN3jYKOQ1Tk
I think this strategy is the best PaaS-like solution you could get. But - unfortunately - this is not supported by any cloud vendor out of the box. But you could set it up on (for exmaple) Amazon very easily.
EDIT
There also exists a Build Pack for Cloud Foundry to setup a Virgo server which can run OSGi apps: https://github.com/glyn/virgo-buildpack
Take a look at Gyrex. It's not a service yet but can be used to build you're own OSGi PaaS cluster. It uses Equinox, p2 for provisioning and Jetty.
http://eclipse.org/gyrex
Disclaimer: I'm a committer and heavy user of it.
There is a commercial provider of OSGi cloud services - Paremus. They have 2 cloud products - Nimble and Service Fabric. You might want to check them out. The Nimble product is available in a limited free edition for trial.
OSGi can be used on pretty much any cloud provider that offers Java support, since it is essentially just a Java library.
The exception to this would be Google App Engine, since they don't just modify Jetty, they modify Java itself and remove the ability to create threads and classloaders, both of which are required for full OSGi support.
OSGi is basically a Java library that can run on a virtual machine that has a JDK/JRE support. But remember one stuff, out of the box support is what you are looking for and you need to customize the PaaS you choose to run your app. I think to do this, you need to choose the provider that is easiest to configure and scale. Try out Jelastic. It is easiest of the lot to cinfigure and get started. Check their jar uploads, and I think it will suffice your needs.
Let me know what you think and if this answer is of any help.
Surya

Apache Felix & Web Start: loading bundles

I've read similar questions but I still don't have all the pieces together.
Is it possible (and if yes how) to start an Apache Felix based OSGi desktop application via Java Web Start?
My main concern is that you have to specify the bundles somewhere in JNLP file if you want to enable the update checks of Web Start (which is a requirement). But the only thing I see that could help is a jar resource. But this would just add jars to the classpath, not starting them as bundles.
Any ideas?
Right, any JARs you list in the JNLP will simply be put on the classpath. There is no way to get Web Start to install them as bundles, because Web Start knows nothing about OSGi.
You could use Web Start to kick off a small launcher application, which consists of just the OSGi Framework and a "management agent" of some kind. That management agent could then use other means (e.g. OBR) to install and update bundles from a repository.
This approach would also help you to eventually migrate from Web Start entirely, which would be for the best since Web Start is obsolete and may not even be supported in future versions of Java.

Mini-OSGi that can run in a sandbox (like AppEngine or WebStart)?

I really like the concept of modular bundles as implemented by OSGi.
I also like "managed deployment" services like Google AppEngine (for web application) or Java WebStart (for client software).
These two ideas seem to complement each-other rather well conceptually.
However, the OSGi standard includes a couple of features that make it impossible for implementations like Felix or Equinox to run on top of sandboxed virtual machines, such as AppEngine or Webstart. In these environments, it is not possible to get direct access to a file system, for example, which precludes the OSGi bundle cache that is used to store persistent bundle state and native libraries.
Now, I have no great interest in using native libraries or have persistent bundle state. Is there some framework that implements the core bundle and services concept of OSGi (ideally in a compatible way so that OSGi bundles can be deployed into it as is), but can work without a bundle cache (and other facilities not available in a sandbox)?
I am looking for something like a limited version of Felix that works on AppEngine or WebStart.
Of course, if the WebStart engine and the Google AppEngine just provided OSGi framework services out-of-the-box that would be great, too...
Update: Another very limiting aspect of AppEngine is that you cannot start new Threads. This prevents (among other things) asynchronous bundle life-cycle management. Obviously not an issue with WebStart.
EclipseSource have a patched version of osgi engine that (kind of) working in AppEngine, download the project zip files from the blog: http://eclipsesource.com/blogs/2009/04/10/osgi-on-appengine/
I'm pretty sure it can be done, and This eclipse help page could probably get you started. If I understand it correctly, your bundles must be signed and your jnlp file needs to request all permissions.
You should talk to Chris Aniszczyk. He made it work with Equinox and Knopflerfish. See the screenshot here: http://twitpic.com/300lk He was planning on blogging about it, but I guess he is pretty busy at the moment. Here is the link to his blog: http://mea-bloga.blogspot.com/
http://code.google.com/p/lemmon/
however, check the issues for URLStreamHandler Problem.
No personal experience, just a clue that might help you.
If your sole problem comes from the bundle cache and you don't need it, you can may be get rid of it by set this property to null in Equinox or Felix ? I'm pretty sure that this cache is not mandatory to have Equinox to run (don't know for Felix)

Categories

Resources