Deploy a war file to a server, such as tomcat or websphere

Hello,

I work in a closed organization, our application does not yet utilize the cloud. I would like to deploy my awesome Vaadin application first to Tomcat so I can demonstrate it running on one of our internal Linux servers. After that, I would like to deploy it to WebSphere to sit alongside the rest of our enterprise applications.

I see deployment instructions for all kinds of cloud platforms, AWS, Microsoft as Azure etc.

I am having a hard time getting a generated war file to run on tomcat 10. Documentation and an example would really help… It would be great if someone created a video demonstrating deployment to Tomcat including using maven to deploy it.

I do not know why it is not working. I have been beating my head against it, is it the versions I am using?, Is it tomcat 10, is it Java 21, or is it just my application start up. I have not really looked at logs. Knowing where to look would probably help.

Thank you

Check the catalina.log file

What are the symptoms? Note that by default Tomcat deploys using the application name as deployment path. Did you use correct url to open the application? Tomcat 10 works at least upto Java 24, I deployed some Vaadin app just last week with that config. Just drop the WAR to webapp folder of Tomcat. Are your deploying on local machine or remotely?

Relevant questions, in addition to Simon’s pointer:

  • How does your project configuration look like?
    • Which exact Vaadin version are you using?
    • Are you using Spring Boot?
      • If yes: Have you looked at a “how to deploy a Spring Boot application to Tomcat” guide; there are many of those on the internet
      • If yes: presumably you’ve switched to using war packaging; have you excluded the Spring Boot’s built-in Tomcat dependency?
      • If no: that’s interesting, what do the logs say?
  • Have you tried creating a dummy starter project and deploying it? If you haven’t, you should do it now. Does that work?
    • If it works: how does it differ from your real project?
    • If it fails: that’s interesting, what do the logs say?
  • How are you doing the actual deployment?
  • What are the symptoms - deployment fails, deployment succeeds but app doesn’t show, something else?

To keep it simple as a first step, I am just transferring the war file to the web apps folder.

It deployers but fails on start up. I will look at the Catalina log and see what it says.

I have changed the application start up as recommended by various topics on the Internet just hoping one would work. So far no luck

I have generated other spring boot hello world war and deployed via ssh. they do start and work.

I am using the latest version of Vaadin, Java 21 and Tomcat 10. Maven 3.4.4.

Once I modify The application.java to run on tomcat, will it still work locally? If not, is there a way to live in both worlds?

I could bet your issue is the “development mode”, which is the default for Vaadin projects (IMO a wrong default). The development mode uses front-end tooling for you behind the scene, so that you can use add-ons, customize the theme etc. dyring the development phase. Server probably doesn’t allow to automatically install front-end tooling (which is a good thing) → failure during start up.

When making an actual deployment, you should prepare the front-end bundle upfront → then the server with minimal tooling works better and the end users have more optimal user experience. Typically this is triggered in Maven built projects using “production” profile:

mvn package -Pproduction

More about production builds here:

BTW. I urge you to find out a way to check the logs on that server anyways, as suggested by @SimonMartinelli. That should contain pretty good error message, or at least some hints about the development mode.

I just downloaded Tomcat 11 and created a new Vaadin project.

Then changed the pom.xml to

<package>war</package>

And adjusted the Spring Boot app class:

@SpringBootApplication
public class VaadinWarApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(VaadinWarApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(VaadinWarApplication.class, args);
    }

}

Built it for production

./mvw package -Pproduction

Copied to the webapps directory and started Tomcat.
All good.

@vaabott I just created a small blog post including an example project.

3 Likes

I cloned your github project and uploaded the resulting war file via scp to our remote linux server running tc10. It worked! Thank you for creating that!

I am comparing what you created with a bare bones project created with start.vaadin. I am comparing the two project to find what the difference is so far I have not figured it out.

I built it using ./mvnw clean package -Pproduction

When i deploy the project I got a couple of errors i need to work through.
I see to have narrowed it down to the fact that I had a theme defined
I removed that and it ran after i added the missing ClockConfig.java for the skeleton ToDo app.

Now i just need to figure out how to add a theme and have it go to the war file.
Maybe that is just automatic.

Thank you so very much for your help and blog!

A couple of follow up questions:

  • Is there an easy way to have the app run locally in my intellij AND build a war file for development? It seems the Application.java is different between the two targets.
    I guess i could just comment out one or the other and change the target from war to jar?

  • I noticed you defined the application class VaadinWarApplication can it be named anything? Such as just plain old Applicaiton.java

Thank you again!

  1. I’ve added a theme and this also works. Check out the updated GitHub demo project.
  2. You can name the class annotated with @SpringBoot whatever you like.
  3. Have a look at the IntelliJ documentation how to run it from the IDE in a Tomcat server: Run/Debug Configuration: Tomcat Server | IntelliJ IDEA Documentation

To make my test app work with it’s theme i added

implements AppShellConfigurator to my application class, just as you did in your github sample!

All good now!

You are the best!

@SpringBootApplication
@Theme(“default”)
public class VaadinWarApplication extends SpringBootServletInitializer implements AppShellConfigurator {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(VaadinWarApplication.class);
}
public static void main(String args) {
SpringApplication.run(VaadinWarApplication.class, args);
}
}

1 Like

I’m glad I could help!