Embed for Vaadin add-on

I have posted a new add-on to the directory. It’s called
Embed for Vaadin
.

As everything we do here internally, we were searching for mechanisms to optimize our daily work tasks. And since we’re also learning Vaadin, we wanted to be able to quickly prototype a layout with some styling to see how it actually show in the browser.

Since the requirements to start a Vaadin application are pretty simple, we got the idea to embed a Tomcat server running a Vaadin application and create a wrapper API on top. The API is extensible and you can also use it in integration tests scenario.

The add-on is already available on the central maven repository so you should be able to grab it from pretty much any environment. The current version relies on Tomcat 7.0.26

For instance, deploying an application showing a button and opening the default browser automatically is as simple as writing this

EmbedVaadin.forComponent(new Button("Hello")).openBrowser(true).start();

See also
this article on our Blog
for more details.

I welcome any further development ideas and bug reports, this could be either discussed here or on Github!

Cheers,
Stéphane

We have just released 0.2

  • Custom WidgetSet can be specified
  • Clearer separation between an embed server deploying a single component and one deploying a full application
  • Development header: ability to shutdown the server and close the tab from the user interface
  • Improved browser support
  • A custom implementation can now expose a custom properties configuration more easily

It may not be clear what you can do with the add-on so we have published
a youtube video
showcasing a one minute hello world.

Since the library requires Tomcat to control the embed server, this add-on is a bit harder to use if you don’t have a dependency management tool such as Ivy or Maven. Note that the add-on has been published on the central repository so you don’t need to configure an extra repository to use it (i.e. the “vaadin add-ons”).

We have just released 0.3

  • Support of Vaadin production mode
  • The development header is no longer added by default. Added an option to enable it
  • Context path is handled the same when it is specifies through the API or loaded from a properties file
  • EmbedVaadinConfig now exposes the deploy URL of the application. This takes into account the actual port that was allocated once the server has started
  • Wrong startup log when a custom HTTP port is specified

We have just released 0.4 which brings support for Vaadin 7. Embed for Vaadin can therefore be used to quickly prototype things with Vaadin 7!

We have also added a simple maven archetype to easily get you started: it holds a project with a simple layout and a way to start Vaadin either from your IDE (using the DemoApp main class), or through a Maven command using the exec plugin (mvn package exec:exec)


Vaadin 6

To use Embed for Vaadin with Vaadin 6, please use the following dependency:

<dependency>
    <groupId>com.bsb.common.vaadin</groupId>
    <artifactId>com.bsb.common.vaadin.embed</artifactId>
    <version>0.4</version>
</dependency>

Or this command line argument to generate a simple project:

mvn archetype:generate  \
    -DarchetypeGroupId=com.bsb.common.vaadin \
    -DarchetypeArtifactId=com.bsb.common.vaadin.embed-simple-archetype \
    -DarchetypeVersion=0.4


Vaadin 7

To use Embed for Vaadin with Vaadin 7, please use the following dependency instead (notice the extra 7):

<dependency>
    <groupId>com.bsb.common.vaadin</groupId>
    <artifactId>com.bsb.common.vaadin7.embed</artifactId>
    <version>0.4</version>
</dependency>

Or this command line argument to generate a simple project:

mvn archetype:generate  \
    -DarchetypeGroupId=com.bsb.common.vaadin \
    -DarchetypeArtifactId=com.bsb.common.vaadin7.embed-simple-archetype \
    -DarchetypeVersion=0.4

As usual, the artifacts are available on the central repository.

0.4 also allows you to open the browser at a customized location. Full changelog and documentation
available here

Cool stuff :slight_smile:

Nice addon and might be quite useful in development.

However when i upgrade my Vaadin.jar to version 6.8.2 (from 6.7.6 the addon’s pom is pointing), i receive the following error.

[font=Courier New]
SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread “main” java.lang.NoSuchMethodError:
com.vaadin.ui.VerticalSplitPanel.setSplitPosition(II)V

at com.bsb.common.vaadin.embed.component.ComponentWrapper.wrapLayout(ComponentWrapper.java:83)
at com.bsb.common.vaadin.embed.component.ComponentWrapper.wrap(ComponentWrapper.java:66)
at com.bsb.common.vaadin.embed.component.DevApplicationServlet.(DevApplicationServlet.java:48)
at com.bsb.common.vaadin.embed.component.ComponentBasedEmbedVaadinTomcat.configure(ComponentBasedEmbedVaadinTomcat.java:58)
at com.bsb.common.vaadin.embed.AbstractEmbedVaadinTomcat.start(AbstractEmbedVaadinTomcat.java:83)
at com.bsb.common.vaadin.embed.EmbedVaadinServerBuilder.start(EmbedVaadinServerBuilder.java:226)
at com.afls.test.ComponentTester.main(ComponentTester.java:13)

[/font]
vaadin.jar 6.8.2 do contain this method but i am not sure why this error. Any help in rectifying this error?

Good catch. Actually we have encountered the same issue already and forgot to create an issue on the github tracker.

There is a binary incompatible change introduced in Vaadin 6.8. setSplitPosition is now taking a float instead of a int. You can disable the development header as a workaround

EmbedVaadin.forComponent(new Button("Hello"))
                .withDevelopmentHeader(false)

Embedding an application is not affected by this issue. I am going to create an issue in Vaadin itself so that they fix this in 6.8.3 (and later). But if they don’t do it, the only option left is to release another version that only works with Vaadin 6.8+ or add a nasty hack and that’s really something I would like to avoid.

Thanks for the report.

Edit: here is the issue http://dev.vaadin.com/ticket/9336

Thanks. The workaround works fine. let me wait for the fix from either side.

We have just released 0.5 which brings support for the latest Vaadin 7 beta ! Be aware that things have been moving internally between beta1 and beta3 so this release only works as from beta3. We have also upgraded to the latest Tomcat release (7.0.32).

Please note that there is still an annoying open issue: the shutdown button with Vaadin7 does not work anymore. This has been reported to Vaadin in #9805

The maven archetype is still available and it allows to easily get you started: it holds a project with a simple layout and a way to start Vaadin either from your IDE (using the DemoApp main class), or through a Maven command using the exec plugin (mvn package exec:exec)


Vaadin 6

To use Embed for Vaadin with Vaadin 6, please use the following dependency:

<dependency>
    <groupId>com.bsb.common.vaadin</groupId>
    <artifactId>com.bsb.common.vaadin.embed</artifactId>
    <version>0.5</version>
</dependency>

Or this command line argument to generate a simple project:

mvn archetype:generate  \
    -DarchetypeGroupId=com.bsb.common.vaadin \
    -DarchetypeArtifactId=com.bsb.common.vaadin.embed-simple-archetype \
    -DarchetypeVersion=0.5


Vaadin 7

To use Embed for Vaadin with Vaadin 7, please use the following dependency instead (notice the extra 7):

<dependency>
    <groupId>com.bsb.common.vaadin</groupId>
    <artifactId>com.bsb.common.vaadin7.embed</artifactId>
    <version>0.5</version>
</dependency>

Or this command line argument to generate a simple project:

mvn archetype:generate  \
    -DarchetypeGroupId=com.bsb.common.vaadin \
    -DarchetypeArtifactId=com.bsb.common.vaadin7.embed-simple-archetype \
    -DarchetypeVersion=0.5

As usual, the artifacts are available on the central repository.

Full changelog and documentation
available here

Hi,

first of all, thanks a lot for your effort on this addon, I find it really useful.

But I’m facing a problem I’m not able to solve. I’ve developed a Vaadin complex component (with database access, Excel process,…) that is working fine from a Tomcat server; but I’ve been trying to generate a stand-alone app using this addon and I got the following error:

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]
.StandardHost[localhost]
.StandardContext
[/xml]]
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]
.StandardHost[localhost]
.StandardContext
[/xml]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 6 more
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.setInitParameter(Ljava/lang/String;Ljava/lang/String;)Z
    at org.apache.catalina.core.StandardContext.mergeParameters(StandardContext.java:5671)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5511)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more

...

Do you hava any idea about the origin of this failure?

Thanks in advance and regards,
Martin

Yes, you have conflicting servlet-api in your classpath. Embed for Vaadin brings a tomcat with it (with a certain servlet api) and your project brings an incompatible one. Please review your dependencies.

Also, if you are using Spring, I’d recommend giving a look at Spring Boot that offers a similar developer experience for everything (not only Vaadin).