Vaadin Flow OSGI support

Hi,

I am trying to use Vaadin Flow in Karaf(OSGI container). And i have a problem with deploying the Vaadin Flow bundles. My problem is with ph-css.

I have installed bundle:install -s mvn:com.helger/ph-css/6.1.3 and bundle:install -s mvn:com.helger/ph-commons/9.3.5(required by ph-css)

But both bundles are on state Installed.
Ph-css says its missing import-packages com.helger.commons and com.helger.css.
And Ph-commons says its missing import-package com.helger.commons.

The screenshot is from Vaadin OSGi Support.
In the documentation it is stated “ph-css require some OSGi features which needs to be deployed at runtime but they don’t depend on them during compilation.”

That is why i am installing ph-commons but the error i get is:
Error installing bundles:
Unable to start bundle mvn:com.helger/ph-commons/9.3.5: org.osgi.framework.BundleException: Unable to resolve com.helger.ph-commons [78]
(R 78.0): missing requirement [com.helger.ph-commons [78]
(R 78.0)] osgi.extender; (osgi.extender=osgi.serviceloader.registrar) Unresolved requirements: [[com.helger.ph-commons [78]
(R 78.0)] osgi.extender; (osgi.extender=osgi.serviceloader.registrar)]

Do you have any ideas which features might do the trick?

Best Regards,
Vladislav

17811962.png

Had the same problem and created an example

http://devblog.mhus.de/2019/08/vaadin-14-with-osgi-and-karaf.html

Hi Mike,

Thanks for your quick reply. With your example i successfully resolved all bundles and was able to install my own UI bundle.
But i get an exception in the front end(see screenshot).
This is my simple code.
Do you have any idea what the problem might be?

MainView

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.server.PWA;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.theme.Theme;
import com.vaadin.flow.theme.lumo.Lumo;

/**
 * The main view contains a button and a click listener.
 */
@Route("")
@PWA(name = "My Application", shortName = "My Application")
@Theme(Lumo.class)
public class MainView extends VerticalLayout {

    public MainView() {
        Button button = new Button("Click me",
                event -> Notification.show("Clicked!"));
        add(button);
    }
}

VaadinServlet

import org.osgi.service.component.annotations.Component;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

@Component(service = Servlet.class,property= "alias=/gui",servicefactory=true)
public class VaadinServlet extends com.vaadin.flow.server.VaadinServlet {

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);

        getService().setClassLoader(getClass().getClassLoader());
    }
}

pom

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>vaadinFlow</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>My Application</name>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <vaadin.version>14.0.2</vaadin.version>
    </properties>

    <repositories>
        <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->

        <!-- Main Maven repository -->
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- Repository used by many Vaadin add-ons: https://vaadin.com/directory -->
        <repository>
            <id>Vaadin Directory</id>
            <url>https://maven.vaadin.com/vaadin-addons</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <type>pom</type>
                <scope>import</scope>
                <version>${vaadin.version}</version>
            </dependency>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>flow-osgi</artifactId>
                <version>${flow.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.core</artifactId>
                <version>6.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.annotation</artifactId>
                <version>6.0.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.cmpn</artifactId>
                <version>6.0.0</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin-core</artifactId>
            <scope>provided</scope>
            <exclusions>
                <!-- Webjars are only needed when running in Vaadin 13 compatibility mode -->
                <exclusion>
                    <groupId>com.vaadin.webjar</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.insites</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymer</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymerelements</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.vaadin</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.webcomponents</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Added to provide logging output as Flow uses -->
        <!-- the unbound SLF4J no-operation (NOP) logger implementation -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>biz.aQute.bnd</groupId>
            <artifactId>biz.aQute.bndlib</artifactId>
            <version>3.3.0</version>
        </dependency>
    </dependencies>

    <build>
        <!--<defaultGoal>jetty:run</defaultGoal>-->
        <plugins>
            <!-- We use jetty plugin, replace it with your favourite developing servlet container -->
            <plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>

            <!--<plugin>-->
                <!--<groupId>org.eclipse.jetty</groupId>-->
                <!--<artifactId>jetty-maven-plugin</artifactId>-->
                <!--<version>9.4.15.v20190215</version>-->
                <!--<configuration>-->
                    <!--<scanIntervalSeconds>1</scanIntervalSeconds>-->
                <!--</configuration>-->
            <!--</plugin>-->

            <!--
                Take care of synchronizing java dependencies and imports in
                package.json and main.js files.
                It also creates webpack.config.js if not exists yet.
            -->
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>14.0.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-frontend</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Production mode is activated using -Pproduction -->
            <id>production</id>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

bnd

Bundle-Name: ${project.name}
Bundle-Version: ${project.version}
Bundle-SymbolicName: ${project.groupId}.${project.artifactId}
Export-Package: com.example
Import-Package: *
Vaadin-OSGi-Extender: true

Forgot to add the screenshot with the error.
17813465.png

I understand that the vaadin plugin compiles all the webjars together to one bundle this meens it’s using the “v13 flow 1 mode” and you need to remove the exclusions under “Webjars are only needed when running in Vaadin 13 compatibility mode” in the pom file.

Thanks for the help! I had to remove the exclusions and add plugins:

org.codehaus.mojo

maven-antrun-plugin

And also i had to to publish my static resources

@Component
public class MyComponentResource implements OsgiVaadinStaticResource {

public String getPath(){
    return "/META-INF/resources/frontend/my-component.html";
}

public String getAlias(){
    return "/frontend/my-component.html";
}

}

Now everything is working.