I work from several months with Apache Felix and Glassfish. I can create simple Web Applications. Now I have to create Java daemon based on OSGI architecture. Is there any good tutorial with example code that can help to learn Apache Felix for Java desktop applications. I also want to ask how the bundles are packaged? Is web applications they are jar files.
I'd say using webstart would be easiest. In that case you'd create a basic jar file containing Felix (and maybe some more libraries) that can start up your application, and from there the client could download additional bundles using Bundle.install. You could also combine it with Apache Felix OBR, that would give you more flexibility, at the cost of some extra infrastructue.
You can also have a look at this, but I think (please correct me if I am wrong) it is Equinox specific.
Finally, JBundle looks promising, I never tried it but it looks relevant for you.
There are many examples in Apache Felix OSGi Tutorial http://felix.apache.org/site/apache-felix-osgi-tutorial.html
Look at bndtools and bnd and any time now jpm: http://softwaresimplexity.blogspot.fr/2012/04/just-another-package-manager.html
Related
I am starting develop modular apps with OSGi framework. My first concern is if I can develop using felix dependencies in my source code then later run my code in Concierge.
I looked for Concierge examples over the Internet, but there is no a good tutorial with examples at least I did not find out something good, please if you know something let me know.
So, my question is simply if I can develop using specifications and run everywhere in terms of platforms (Concierge, Felix, and others).
Thanks in advance for your support on it,
Regards,
-Rod
The OSGi specifications are split into three parts:
Core: These specifications are normally implemented by the OSGi framework. I am not sure if every framework supports all specs but until now I did not spot any that were not supported. So typically these are always available.
Compendium, Enterprise: These specifications are normally supported by specific bundles. So you have to make sure to install a bundle that implements the spec you want to use. For example you can install felix config admin if you want to use the configuration admin spec. Normally you can mix these like use equinox framework but still install felix config admin.
I have to create a project for school. We want to create a system that monitors sensors. Since sensors develop very much, there is the possibility that they use other sensors in a couple of years. To capture that problem, we want to create a system that lets users write plugins to monitor the sensors.
I am looking at different frameworks, mainly OSGI.
Could someone tell me the difference between Apache Felix and OSGI? Also, is OSGI still active?
Thanks!
OSGi is a set of specifications, which are developed and released by an industry consortium called the OSGi Alliance.
Apache Felix is a project in which several of the OSGi specifications are implemented. So whereas OSGi gives you a specification (essentially a PDF document!), Apache Felix is actual software that you can run. Because Felix conforms to the OSGi specification, any code that you write to run on Felix will also run on any of the other OSGi implementations. These include Eclipse Equinox, Knopflerfish and Concierge.
Yes OSGi is very active, and is particularly relevant to your requirements. Large companies (e.g. Bosch, Deutche Telekom, Huawei) are using it to build IoT systems and shipping them to people's homes, vehicles etc right now.
You might also look at Eclipse Kura, which builds IoT functionality e.g. device communications on top of OSGi.
How would you implement a Plugin-system for your Java application?
Is it possible to have an easy to use (for the developer) system which achieves the following:
Users put their plugins into a subdirectory of the app
The Plugin can provide a configuration screen
If you use a framework, is the license compatible with commercial developement?
First you need an interface that all plugins need to implement, e.g.
public interface Plugin {
public void load(PluginConfiguration pluginConfiguration);
public void run();
public void unload();
public JComponent getConfigurationPage();
}
Plugin authors should then bundle their plugins into JAR files. Your applications opens the JAR file and could then use an attribute from JAR manifest or the list of all files in the JAR file to find the class that implements your Plugin interface. Instantiate that class, the plugin is ready to go.
Of course you may also want to implement some kind of sandboxing so that the plugin is restricted in what it can and can not do. I have created a small test application (and blogged about it) that consists of two plugins, one of which is denied access to local resources.
Use OSGi.
It is the foundation of the Eclipse plug-in system. Equinox is Eclipse's implementation (licensed EPL) and Felix is the Apache Project's implementation (licensed Apache Public License).
Eclipse provides a concrete example that OSGi can cover the points you mentioned (or you could just build your application on top of Eclipse RCP if you want a full Eclipse/SWT/JFace stack).
Since 1.6, there's been java.util.ServiceLoader which can be used if you want to code your own simple system.
But if you want anything more than basic features, use one of the existing frameworks.
Use PF4J.
It has support for Web, Spring and Wicket.
Easy to use and build the applications
There is also JPF (Java Plugin Framework).
I worked on OSGi for a week--an intense, nothing but OSGi week. At the end it was like a bad dream but I learned a lot.
I was able to get OSGi working (not easy, all examples are out of date, everything on the net is at least three years old if not five), but I had serious trouble getting it integrated into an existing project because of issues with the jar manifests.
In short, there are only a few obscure tools used for building manifests and they are not well documented (BND Tools is hardly obscure, but it is designed for a certain process in Eclipse). Also, most of the OSGi information available is not targeted towards application developers who have an existing desktop application.
This makes a lot of the context for the information foggy or inappropriate. Neil Bartlett's blog posts were the biggest help, but even those failed to get a working system (I grabbed some code from the Felix tutorial and pieced it together to get the embedded framework rolling). I found his book draft that he posted for free years ago, which is excellent, but the examples in Eclipse do not work because of changes in Eclipse OSGi support.
I think that recommending OSGi for solving the above stated problem is extremely poor advice. OSGi is "the right choice" but for a scenario as the one above, I think either JPF or some homegrown minimalistic framework is sufficient.
Years ago I started a project like that and I hope soon will be ready.I got inspired by projects like NetBeans and Eclipse but meanwhile it changed to something a little bit different. OSGi looks like a good choice now, but I didn't had a chance to compare it with my project.It is similar with JPF mentioned above, but in the same time different in many ways.
The basic idea which motivated me is to be as easy as possible to build Java application, with no separation between web applications, desktop applications or applet/JWS applications(of course this doesn't cover the UI - yet) as a core functionality.
I built the project with a few goals in my mind :
it doesn't matter if you build a web application or a desktop application you should start the application in the same way, a plain main method, No fancy web.xml declaration(not that I'm against having a standard web descriptor, but it doesn't go well with a plug-in system, where you add "servlets" - I call them RequestHandler(s) - dynamic at your will).
easy to plug in "extensions" around an "extension point" - something from Eclipse but a different approach.
self-deployable, since all the plugins are registered(XML files) the application must be self-deployable independent of the build system - of course there is an Ant task and a Maven MOJO which are the links with the ourside world, but in the end it calls the application and instruct it to self-deploy itself at a specific location.
borrowed from Maven, it can download code from repositories(including Maven 1 & 2 repositories) so your application can be deployed as a single small jar as long as you have access to the repositories(useful sometime, and basically this provides support for auto-updates - don't you love the idea to be notified by your web application that there is a newer version, it was downloaded and it just needs your permission to install it? I know I love that).
basic application monitoring about system health, email notifications in case of failures
Please give an advise on how to do "plugin" architecture for Java web application.
Currently we are using quite simple and standard Spring+Hibernate+Struts 2 in Tomcat servlet container. (Built with maven)
I need something like Redmine. Where any module can be enabled/disabled, updated
Please exclude heavy options like OSGi, Portlet.
OSGi is too heavy, there is no good adoption of the technology for web. I already looked at Eclipse Germini;
Portlet it just old, and never was popular.
I will try to provide several possible solution. I did spent some time preparing small PoCs for the project I'm working on, so let's hope the options below are relevant.
Important note: it is really easy to define some extension point, do resolve and find available implementations. There are a lot of solutions available, for example good and simple one -- JSPF
Resources are the main problem for WEB applications
OSGi
OSGi, is not that bad and can be useful. It seems to be heavy (and some implementations are heavy) but this is price of standardized platform. I would suggest to check Apache Felix. It can be used in a "lightweight" mode. By the way, it includes Web Console which is build as loosely coupled plugin-based application, could be helpful:
Some examples Extending the Apache Felix Web Console
The Web Console can be extended by registering an OSGi service for the
interface javax.servlet.Servlet with the service property
felix.webconsole.label set to the label (last segment in the URL) of
the page. The respective service is called a Web Console Plugin or a
plugin for short.
You can also check eie-manager which is clean and simple and uses OSGi to manage plugins. Could be a good example for you.
Custom plugin framework
I would suggest to review solution behind Jenkins/Hudson. I would say Jenkins plug-in system is quite mature and reliable. Can be used as a good example.
Please also check Hudson Plugin Architecture
Simple solution
For my project I've build plugin abstraction layer based on JSPF with custom dependency resolver.
PROS:
simple and small
clean concept
works good
CONS:
without proper plugin management can be slow (full classpath search)
provides very basic functionality
may require additional attention
I would suggest to use JSPF only if you really need some simplicity and want to control everything. JPF provides a lot of interesting features out of the box, for example:
Plug-ins can be "hot-registered" and even de-registered during
application execution. What's more, registered plug-ins can be
activated and deactivated "on the fly", minimizing runtime resource
usage.
The problem is JPF is dead.
Suggestion
Do spend some time with Apache Felix. It is mature enough, so your time investments may pay back a lot.
Check out the answers to this question: Best way to build a Plugin system with Java
If you don't trust the plugin code, you can implement sandboxing, as described here: Sandbox against malicious code in a Java application
The open-source Java Plug-in Framework project supports plugin deactivation, you can get inspired from it even if it is too heavy for your purposes.
Atlassian open sourced their plugin system here. I see it is being worked heavily by Atlassian team. Worth to explore its documentation
I have an application that I am converting to OSGi, and there are a couple of
bundles that are required (for now). These are jars that are included in the
program distribution. What is the best way to install these? I was looking
at using a classpath:xxx.jar, but is there a better way to do this?
thanks,
Lance
I'm guessing that you want an easy way to start up your application, without having to install all bundles from the console at every startup. If that is your current problem, you can take a look at
http://paxrunner.ops4j.org/space/Pax+Runner , which eases the launching of the framework and deploying the bundles into it, or
http://njbartlett.name/bndtools.html , an excellent Eclipse plugin that helps you during development.
Another approach that could be satisfying is to create a feature containing all your bundles. See for a hint here. A feature is a package of bundles and it allows you to install a bunch of bundles with one command.