Eclipse

50 posts

Development for and with Eclipse

Releasing “Package Drone” 0.0.1

A package repository for Maven Tycho, OSGi and all the rest.

Itch: I want to have a software repository where Maven Tycho can deploy to and P2 can read from. Also I would like to re-use this repository as an OBR or OSGi R5 repository, and possibly as Maven repository.

Scratch: Package Drone, version 0.0.1

Now there already is the Nexus Repository and the Nexus Unzip Plugin. However this essentially uploads a full P2 repository ZIP file and uses Nexus as a plain web server, hosting that zipped P2 repository.

Instead I would like to not only have a P2 repository, but also an OSGi R5 repository, based on the same OSGi bundles uploaded. I would also like to upload bundles created by the Maven Bundle Plugin, or BNDtools. Also would I like to make a full, Maven like, release using Tycho and later host this as a Maven 2 repository. Now package drone is not quite there yet, but the basic Tycho Deploy -> P2 Consume workflow already works to some degree.

Package Drone is hosted on github and there is a small readme and wiki.

Be warned, this is alpha quality software. If it works for you, fine. If not please help me fix it!

OSGi EE – Modular Web Applications

Creating a modular web application in Java still is a tricky task. While there has been some improvement with web fragments, this still is far away from what you actually want.

But what is it that you (or better I) want:

  • Modularity – Make the application extensible using plugins. Not just one big block. Install additional functionality with a few clicks
  • Easy setup – Setting up a JEE server like JBoss can be a pain in the ass. First you have to configure your datasource with some obscure XML file. It would be way better to be directed to some sort of setup screen, asking for all database (etc.) information first. Guiding you through a setup process. With JEE your web application won’t even start if your JPA data source cannot be loaded since the driver is not specified.

Now there are a lot of applications which provide this flexibility. Atlassian, Jenkins, and a few more, all do a great job. Most PHP web applications guide you through a web setup when you first install the software. So why can’t Java do this out of the box?

When you think of modularity and services, OSGi immediately comes into my mind. However “the Web” still is a strange place for OSGi setups. Yes you can register a servlet with OSGi and access it through “http”. But that is just the start. You want JSP, Form Validation, maybe even Spring WebMVC.

There are a few setups I stumbled over, pax runner with pax web. However they bring in a pretty old jetty 7, when there is jetty 9.2.x with Servlet 3.1 support. There are some Apache Karaf tutorials, however there is also no JSP support, just a custom Vaadin bridge.

Jetty 9.2.x claims to have OSGi support out of the box. In combination with Eclipse Equinox this should be an easy setup. And although it really works, you know what you have to do. I got it working in the Eclipse IDE, but it still provides most things you really want.

In order to be able to reproduce it myself, I made a few ant script and sample projects out of what I learned and decided to put them up on github.

So if you want to build modular web applications with Jetty, Equinox, Eclipse, Hibernate Validation, Spring WebMV and more (with a recent version of all components) you can have a look at https://github.com/ctron/osgiee.

If you have more examples working or find a bug, please let me know ;-)

Fixing the theming issue with Eclipse RCP applications in E4

It seems that migrating from Eclipse RCP 3.x to E4 (Eclipse 4.x) is not a quick win. If you already have an RCP based application the switch to E4 turns out to be a real problem. As is the E4 way if you want some sort of “custom” application that features some IDE components (like a perspective switcher or about dialog). It seems a bit strange that the migration from 3 to 4 is such a bumpy ride. Although there a are lots of tutorials, they mostly only scratch the surface of the task to convert a full blown RCP application. But this should be a rant on E4, I hope that the next releases improve that situation a lot.

When I migrated our RCP Application (OSTC from openSCADA) to E4 using the RCP bundle of E4. This seems not to be a real E4 application, but allows one to run a legacy, 3.x, application inside the new E4 environment. A quick it-just-works migration, still you miss all the E4 fun. But at the first start the user interface looked up bit garbled up. Some black line drawing artifacts. The tabs where a bit “dull” compared to the facy new tabs in E4.

The solution was pretty simple, the final RCP application was missing the bundle “org.eclipse.platform” which contained the themes and the necessary resources.

Fixing the Mint-X theme for Eclipse/SWT

If you are running Mint, Eclipse and you like the Mint-X theme, you might be a bit frustrated every time you open up Eclipse. Especially with Eclipse 4.2 the design of the toolbars is pretty messed up. See the launchpad bug entry: https://bugs.launchpad.net/linuxmint/+bug/1168281

eclipse1

Gladly this is only a minor glitch which can be fixed easily. Hopefully the change of the github pull request will find its way into Mint.

Access to WMI in Java using Eclipse SWT OLE integration

Today I ran into a problem which could easily solved using a short WMI query. The problem was that the query must be executed within a Java UI application. Googling for a solution I came only up with either quite some ugly workarounds (like generating a VBScript fragment, forking off the VBScript runtime and parsing the result) or some full blown COM/DCOM interfaces (like J-Integra or J-Interop). Although I really like J-Interop (we are using it for DCOM when accessing OPC server in OpenSCADA Utgard) it has some drawbacks. For J-Interop every access (even local access) is a network based access. Since J-Interop only supports DCOM it is free of any platform specific code but required the machine to be accessible using “remoting” functionality (DCOM). Since I wanted to query the WMI from a UI application and I am sure that the WMI query will stay on the Win32 version of the application I was not keen on adding “remoting” as a requirement to the UI application.

After some digging I remembered that SWT brings an OLE interface which provides direct COM access. So I started poking around and finally come up with a solution that works quite well.

For the impatient: The full source code is available from github https://github.com/ctron/wmisample and the screenshot is here.

Continue reading

Eclipse Install Issue

I just stumbled over a strange issue when installing an additional plugin into a fresh Eclipse installation:
An error occurred while collecting items to be installed
session context was:(profile=SDKProfile, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).
No repository found containing: osgi.bundle,org.eclipse.team.cvs.ssh,3.2.100.I20090508-2000

I was unable to add any new plugin and searching Google for help was not successfull. There was an issue somewhere in the Eclipse Bugzilla that the plugin org.eclipse.team.cvs.ssh was optional and no longer installed or required. Seems that P2 thinks the somewhat required for the installation process.

ButI found one hint that deactivating the option “Contact all update sites during install to find required software” helps. And it did.

Screenshot of Eclipse Dialog

Combo viewer requirements

Today I tried to create a combo viewer in Eclipse with a different approach than the it seems the widgets was designed. I have an object which has to main properties an ID and a descriptive name. While this is nothing unusual following requirements seems to be:

The list of the combo box should show the label while the text input field of the combo box should show the id of the object. Using Eclipse Databinding this seems to be an impossible task (if you know a way please post it at stackoverflow). Continue reading

Reading Object Streams in OSGi

Reading an object from an ObjectInputStream is easy. But using OSGi it can be a little bit more difficult. Due to the class loader system of OSGi the ObjectInputStream might not know the class that was stored. Assume you have a Bundle A, B and C. B provides the storing capabilities that stores objects somewhere and C provides the data object itself. Now if A tells B to store some object from C this will not be a problem, since the object class is attached to the object instance. But reading back the object will result in a ClassNotFoundException since B has no reference to C and therefore does not know any classes of C.

One solution of course would be to add a dependency from B to C. But that is probably not what you want. Another way would be using Eclipses “Buddy” policies workaround for problems like this. In this case the bundle B would declare itself capable of working with the buddy system and C would declare itself a “buddy of B”. This turns around the reference. While this is a possible way if you cannot change the logic in B (like existing third party libraries that have to be used) it also has some drawbacks. First of all you commit to using Eclipse/Equinox since this is not covered by OSGi. Also you still have to declare those dependencies from C to B.

On the other hand you can sub-class the ObjectInputStream and override “resolveClass” to let the bundle resolve the class instead of the “current” classloader. Passing the bundle A to that input stream you would have all the classes you need.

Check out the following sample implementation:


import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

import org.osgi.framework.Bundle;

/**
 * An object input stream which loads its classes from the provided bundle.
 * @author Jens Reimann
 *
 */
public class BundleObjectInputStream extends ObjectInputStream
{
    private final Bundle bundle;

    public BundleObjectInputStream ( final InputStream in, final Bundle bundle ) throws IOException
    {
        super ( in );
        this.bundle = bundle;
    }

    @Override
    protected Class<?> resolveClass ( final ObjectStreamClass desc ) throws IOException, ClassNotFoundException
    {
        return this.bundle.loadClass ( desc.getName () );
    }

}

Equinox Remote Terminal Console

Although Equinox offers some sort of remote TCP console it is not what you actually want to have. Being limited to one session, having not authentication and allowing the user to execute any command and shut down the OSGi container is not an option for a productive system.

In OpenSCADA we faced the same problem so we simply developed an OSGi Remote Console based on Apache Mina.

Our equinox console works around the limits of the original OSGi TCP console and can simply be dropped in as a replacement.

SVN Link to the project: http://pubsvn.inavare.net/openscada/modules/aurora/trunk/org.openscada.osgi.equinox.console/

Also we played a little bit with an IRC bot that exposes the OSGi console of Equinox to an IRC server. This is not really tested and just a proof of concept. But it works. If you like check out http://pubsvn.inavare.net/openscada/modules/aurora/trunk/org.openscada.osgi.equinox.ircbot/ and play with it ;-)