Osgify Vaadin Charts

Hi,

I’m working on a POC using Vaadin 7 + Vaadin Charts in an OSGi Web Application.
Everything worked fine till I tried to use Vaadin Charts.
This add-on isn’t available as OSGi bundle. So I tried to Osgify it. And I failed.
After first attempt, result was the following :

Widgetset does not contain implementation for com.vaadin.addon.charts.Chart. Check its component connector’s @Connect mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions.

For the second attempt, I’ve pre-compiled this addon and added resulting widgetset into OSGI Vaadin Charts bundle.
Still have the same error.

For the third attempt, I tried to use following tutorial : http://redvoodo.wordpress.com/howto/howto-use-vaadin-add-ons/.
Resulting error is :

java.lang.NoClassDefFoundError: com/vaadin/ui/AbstractComponent

Is there an easy way to OSGify add-ons working with compiled widgetsets ?

Regards

Hi Ghislain,
I don’t know your definition of easy, but mine has never applied to anything to do with OSGi!
Here’s how we got the Charts AddOn working (and a few others too, with similar methods).

Make a new maven project with the following pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>your.group.id</groupId>
	<artifactId>osgi.vaadin.charts</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>bundle</packaging>
	<name>OSGified Vaadin Charts</name>

	<dependencies>
		<dependency>
			<groupId>com.vaadin.addon</groupId>
			<artifactId>vaadin-charts</artifactId>
			<version>1.0.0-beta1</version>
			<scope>compile</scope>
		</dependency>
	</dependencies>


	<repositories>
		<repository>
			<id>vaadin-addons</id>
			<url>http://maven.vaadin.com/vaadin-addons</url>
		</repository>
	</repositories>
	
	<build>
		<plugins>
			<plugin>    <!-- (2) START -->
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<extensions>true</extensions>
				<configuration>
					<instructions>
						<Export-Package>com.vaadin.addon.charts.*, com.vaadin.addon.timeline.*</Export-Package>
						<Import-Package>!com.google.gwt.*, !com.vaadin.client.*, *</Import-Package>
					</instructions>
				</configuration>
			</plugin>    <!-- (2) END -->
		</plugins>
	</build>
</project>

Use a single OSGi project to serve all the WidgetSets in a combined compilation, whose pom looks like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<artifactId>web.widgets</artifactId>
	<name>Vaadin Custom Widget Bundle</name>

	<parent>
		<groupId>your.group.id</groupId>
		<artifactId>whatever.artifact.sets.up.your.vaadin.compilation.and.bundlor.etc.configuration</artifactId>
		<version>x.x.x</version>
	</parent>

	<dependencies>
		<dependency>
			<groupId>com.vaadin.addon</groupId>
			<artifactId>vaadin-charts</artifactId>
			<version>1.0.0-beta1</version>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>com.vaadin</groupId>
			<artifactId>vaadin-client-compiler</artifactId>
			<version>${vaadin.version}</version>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>com.vaadin</groupId>
			<artifactId>vaadin-client</artifactId>
			<version>${vaadin.version}</version>
			<scope>compile</scope>
		</dependency>
	</dependencies>


	<build>
		<resources>
			<resource>
				<directory>${basedir}/src/main/java</directory>
				<includes>
					<include>**/*.java</include>
					<include>**/*.gwt.xml</include>
					<include>**/*.properties</include>
				</includes>
			</resource>
			<resource>
				<directory>${basedir}/src/main/resources</directory>
			</resource>
			<resource>
				<directory>${basedir}/src/main/webapp</directory>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<groupId>com.vaadin</groupId>
				<artifactId>vaadin-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>com.springsource.bundlor</groupId>
				<artifactId>com.springsource.bundlor.maven</artifactId>
				<configuration>
					<failOnWarnings>false</failOnWarnings>
					<outputPath>${project.build.outputDirectory}</outputPath>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

The settings are so that the compiled webapp, e.g. VAADIN.etc is included in the jar. I haven’t fixed this yet, but because of the ordering of the build goals you have to build this twice for the VAADIN resources to be included, sorry!

OSGiWidgetSet.gwt.xml:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module>
	<inherits name="com.vaadin.DefaultWidgetSet" />
	<set-configuration-property name="devModeRedirectEnabled" value="true" />
    <inherits name="com.vaadin.addon.charts.Widgetset" />
    <inherits name="com.vaadin.addon.timeline.gwt.TimelineWidgetSet" />
</module>

template.mf:

Manifest-Version: 1.0
Bundle-Name: Vaadin Custom Widget Bundle
Bundle-ManifestVersion: 2
Bundle-SymbolicName: your.group.id.web.widgets
Excluded-Imports: *
Excluded-Exports: your.group.id.web.widgets.web.widgets.internal
Export-Package: VAADIN.widgetsets.your.groupid.web.widgets.OSGiWidgetSet,
 VAADIN.widgetsets.your.groupid.web.widgets.OSGiWidgetSet.deferredjs,
 VAADIN.widgetsets.your.groupid.web.widgets.OSGiWidgetSet.com_vaadin_addon_timeline

Then, in an application maven project:


		<dependency>
			<groupId>your.groupid</groupId>
			<artifactId>osgi.vaadin.charts</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<exclusions>
				<exclusion>
					<artifactId>vaadin-charts</artifactId>
					<groupId>com.vaadin.addon</groupId>
				</exclusion>
			</exclusions>
		</dependency>

and:

Import-Package: your.groupid.web.widgets;version="2.4.0"

I’ve probably missed something, so please come back with any questions.

Cheers, Dan.

Ah, I remembered another step. You also need to export a package from the template.mf which is only generated at compile time, so it changes. It’s the, for example, deferredjs.36E8E36DE685B91A70CDA1F4B8EEDC4F package. I’ve been adding it in manually, but if that’s too stupid for you, you can wrap the whole thing in a bnd project and get it to automatically export this package.

Hi,

Thanks for your message. It helped me a lot !
I hope Vaadin Team will provide soon an alternate and more production friendly way to use add-ons in an OSGi project.

Ghislain

Hi,

I have practically no experience with osgi, so it would be great to have some help here. I added this rule to build script:
http://dev.vaadin.com/changeset/0000025898/svn

I mostly let maven-bundle-plugin do the job, but tried to exclude all GWT stuff that is only needed during widgetset compilation. I assume nobody does that with osgi. I’d appreciate if some osgi heavy user could give the SVN version a try and report how it works. Thanks in advance.

cheers,
matti

Hi Matti,
I haven’t the time to test it right now, nor likely in the near future, though the change makes sense to me.
Thanks a lot!
Dan.

Hi Ghislain, I just started doing the basically the same thing as you did and I am running into some trouble, are you willing to share your project?

Hi,

Did any osgi user try the SVN build of 1.1 yet? A fresh build is here also:
https://dl.dropboxusercontent.com/u/4041822/vaadinstuff/vaadin-charts-1.1.0-SNAPSHOT.jar

cheers,
matti