Sven Ruppert

HelloWorld - with Apache meecrowave - Ramp up in a second

A nano project to start a Vaadin project. Perfect for Micro-UIs packed as fat jar in a docker image. This will be used in some of the tutorial implementations.

Download the code from GitHub to get started.

Target of this project

The target of this project is a minimal rampup time for a first hello world. Why we need one more HelloWorld? Well, the answer is quite easy. If you have to try something out, or you want to make a small POC to present something, there is no time and budget to create a demo project. You don’t want to copy paste all small things together. Here you will get a HelloWorld-Project that will give you all in a second.

Clone the repo and start editing the class VaadinApp or BasicTestUIRunner. Nothing more.

How does it work?

This project will not use any additional maven plugin or technology.

Here we are using the plain meecrowave as Servlet-Container. http://openwebbeans.apache.org/meecrowave/index.html

But let’s start from the beginning.

Start the Servlet-Container (Java)

The class BasicTestUIRunner will ramp up the Container.

Here all the basic stuff is done. The start will init. a ServletContainer at port 8080. If you want to use a random port, use randomHttpPort() instead of setHttpPort(8080); The WebApp will deployed as ROOT.war.

public class BasicTestUIRunner {
  private BasicTestUIRunner() {
  }

  public static void main(String[] args) {
    new Meecrowave(new Meecrowave.Builder() {
      {
//        randomHttpPort();
        setHttpPort(8080);
        setTomcatScanning(true);
        setTomcatAutoSetup(false);
        setHttp2(true);
      }
    })
        .bake()
        .await();
  }
}

After this you can start the app invoking the main-method.

The UI itself

The UI itself contains not so many elements. There is only a button you can click. For every click, the counter will be increased. The component will be registered under the root-path, based on the Annotation @Route("") Form ore informations about the routing itself have a look at https://vaadin.com/docs/flow/routing/tutorial-routing-annotation.html

@Route("")
public class VaadinApp extends Composite<Div> {

  private final Button         btnClickMe   = new Button("click me");
  private final Span           lbClickCount = new Span("0");
  private final VerticalLayout layout       = new VerticalLayout(btnClickMe, lbClickCount);

  private int clickcount = 0;

  public VaadinApp() {
    btnClickMe.addClickListener(event -> lbClickCount.setText(valueOf(++clickcount)));

    //set the main Component
    System.out.println("setting now the main ui content..");
    getContent().add(layout);

  }
}

Happy Coding.

Vaadin is an open-source framework offering the fastest way to build web apps on Java backends
GET STARTED

Comments (1)