deploying to a Tomcat server

I’m evaluating Vaadin at the moment and performed first steps like running the tutorial application locally as a run on jetty Maven project.

Next goal I’d like to achieve is deploying the application to a server that runs in my network (Tomcat).

What would I have to do?


Christoph

Run “mvn package” and deploy the generated .war file (which you can find from the /target/ directory) using 1) the admin console, 2) hot-deployment folder or 3) deployment script.

-Olli

Thanks. Where do I run that “mvn package”, assumed I have Eclipse running on host A (development) and the deployment server (Tomcat7) on host B. By 1) you mean the tomcat admin console? Neither I know of 2) or 3).
Can you explain?

Christoph

You can run mvn package in the same place where you run the Jetty plugin. On the command line, you can execute it at the project root. If you’re using the Eclipse plugin, select Maven Build… and type package in the goal field. By admin console I mean the Tomcat admin console, yes; if you have the proper access rights, there should be a place where you can upload a .war file to deploy. Ask your Tomcat admin for more info.

Hope this helps,
Olli

Thanks. Just “package” in the goal field. Seems something got been built:

[INFO]
 --- maven-war-plugin:2.6:war (default-war) @ designerdemo ---
[INFO]
 Packaging webapp
[INFO]
 Assembling webapp [designerdemo]
 in [C:\Users\kuku\workspace\designerdemo\target\designerdemo-1.0-SNAPSHOT]

[INFO]
 Processing war project
[INFO]
 Copying webapp resources [C:\Users\kuku\workspace\designerdemo\src\main\webapp]

[INFO]
 Webapp assembled in [832 msecs]

[INFO]
 Building war: C:\Users\kuku\workspace\designerdemo\target\designerdemo-1.0-SNAPSHOT.war
[INFO]
 ------------------------------------------------------------------------
[INFO]
 BUILD SUCCESS
[INFO]
 ------------------------------------------------------------------------
[INFO]
 Total time: 12.279 s
[INFO]
 Finished at: 2016-11-02T17:24:03+01:00
[INFO]
 Final Memory: 25M/246M
[INFO]
 ------------------------------------------------------------------------

So then I put up
designerdemo-1.0-SNAPSHOT.war
to tomcat.

Looks good, good luck with your project!

OK. Fine. I uploaded the generated WAR-file to the server and put it into c:\Program Files\Apache Software Foundation\tomcat7\webapps and it got deployed on the fly as expected.

I now made the deploy directory a share on the server allowing me to have full access to that directory over the network.
How can I make Eclipse use this directory as a target? Or can I run some kind of postbuild script that copies over the WAR file?


Christoph

I still have a slight problem. I found that my designerdemo (which I created as a single vaadin-archetype-application project)
has under Java Resources:
src/main/java
com.example.designerdemo
ApplicationDesign.java
MyUI.java

As a result, since the MyUI.java contains the click button example, my webapp came up with the click button example instead of the ResponsiveApplication code.

Following the example https://youtu.be/-6Ix8WHgD6g I can see that they have a DesignerDemoUI.java in the src tree.
Where does it come from and what is its contents?

What is done in the main java code to make the email client example pop up?

I’m missing the bridge between the java main program and the Vaadin Designer example.


Christoph

Hi,

That DesignerDemoUI is just basically your MyUI with a different name. There are only a couple of steps you need to take:

  1. Create a new java class that inherits your ApplicationDesign class (let’s call it MyApplicationDesign). Initially, it doesn’t even need to have anything in it. You’ll just need it later once you start adding functionality, as ApplicationDesign.java is autogenerated from your design file and will be overridden if you make changes to the visual side.
  2. In MyUI.java’s init method, create a new instance of MyApplicationDesign and add it to the UI. Something like follows:
    @Override
    protected void init(VaadinRequest vaadinRequest) {
        VerticalLayout layout = new VerticalLayout();
        MyApplicationDesign design = new MyApplicationDesign();
        layout.addComponent(design);
        setContent(layout);
    }

Great! Thanks. It works. I’m running the little email client example now under tomcat7 on the remote machine.
(BTW, not yet being acquainted with Eclipse: is there a way to run a postbuild script in the build?) Excuse me when I’m deviating a bit from the topic.

In the first place, while I was looking into the Class MyApplicationDesign seeing “HorizontalLayout” there, I thought I’d be clever and use HorizontalLayout in the MyUI class but it failed. The Class was unknown there. Why then does “VerticalLayout” work? Is everything initially a “VerticalLayout”, even if an HorizontalLayout is packed into it later? Or what’s peculiar to VerticalLayout?

 @Override
    protected void init(VaadinRequest vaadinRequest) {
       HorizontalLayout layout = new HorizontalLayout();
        MyApplicationDesign design = new MyApplicationDesign();
        layout.addComponent(design);
        setContent(layout);
    }

I don’t have any solid ideas about postbuild script running; maybe the Maven Resources plugin? See
https://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html

As for VerticalLayout, there’s nothing special in it; it’s similar to HorizontalLayout. You don’t even really need a Layout in the UI class there, the design component itself would have been good enough for the setContent() method. The unknown class might be because of a missing Java import - the default MyUI class imports a VerticalLayout so that’ll work without the extra added import line.

-Olli