This project demonstrates how you can build modular web applications using Vaadin Flow and Apache Karaf. The project can also be used as a starting point to create your own Vaadin Flow application bundle for Karaf.
For more Vaadin usage samples, you can go to vaadin.com/start.
To access the project directly from github, clone or download the repository and import the project to the IDE of your choice as a Maven project. You need to have 11 installed.
The project consist of four sub-projects:
The main-ui
project contains the code for Web Application Bundle (WAB) which can be deployed
to any OSGi container. This is also the Karaf feature that gets packaged during the build. The most relevant parts are two views that it contains:
The module also provides a simple menu and MainLayout for other bundles that can contribute views to the UI, and Vaadin boiler plate to configure app for PWA features, server push, missing views etc.
The greetservice-api
project provides an API for a dummy service used by the main-ui project.
The greetservice-impl
project provides an implementation for GreetService, that is defined and used by the MainView in the main-ui
project. The main-ui does not depend on this bundle and it is not required to run the project. But deploying it separately affects how the application behaves.
The help-view
is another optional bundle which contains an optional view (and a route target). It can be deployed or un-deployed at any time. The help view will be available in the main-ui
project and its menu only if the help-view
bundle is deployed.
The simplest way to start the project is run command mvn install
to install project artifact and
mvn -pl main-ui install -Prun
to run Karaf OSGi container. After a while, the Vaadin UI will be available in http://localhost:8181. Note that this only deploys the main-ui bundle, and not the optional help-view or greetservice-impl bundles.
For more dynamic tutorial we suggest to follow these steps:
mvn install
./bin/karaf
from the Karaf directoryfeature:install http war
to install required web capabilitiesfeature:repo-add mvn:com.example/main-ui/1.0.0-SNAPSHOT/xml/features
and feature:install main-ui
. This deploys the main-ui and all required dependencies.bundle:install mvn:com.example/greetservice-impl/1.0.0-SNAPSHOT
and bundle:start greetservice-impl
Optional
view (defined in ServiceDependantView Java class) appeared in the menu. Nothing needs to be done at the browser, because Vaadin takes care of updating the UI using the WebSocket based "server push" connection. Try the button again and you'll see that the click listener now responds differently as an implementation for GreetService is available.bundle:install mvn:com.example/help-view/1.0.0-SNAPSHOT
and bundle:start help-view
See readme files starter/README.md and help-view/README.md in the projects for further details.
Vaadin application generally contains dependencies to other bundles: e.g. Vaadin components like Button
,
TextField
, etc. Every Vaadin component is based on a Web Component which
is represented by frontend resources. All frontend resources are built into a bundle
along with Vaadin WAB. As a result:
build-frontend
is run and the WAB is redeployed to get the static frontend bundle updated.Here is a list of things which are not currently supported:
Artifact deployed
message appears in the terminal, requesting http://localhost:8181
would result in a 404 error.
There can be two cases when this happens:
main-ui/target/karaf/data/log/karaf.log
, it seems that multiple port binding exceptions are reported all the times (even while the application is responding normally) which might be related to 404 errors, but currently there is no fix or workaround available for this.
See https://github.com/vaadin/vaadin-flow-karaf-example/issues/100:warning: At the moment, it is not possible to modify frontend resources on the fly (webpack dev server is not available at runtime). This means that for every frontend change, you have to rebuild the frontend bundle. (Issue for devmode)