Basic Deployment
| Make sure your  It is required for production builds. | 
Creating Executable JAR
Open the terminal in the project root folder and execute the following command:
./gradlew -Pvaadin.productionMode=true bootJargradlew "-Pvaadin.productionMode=true" bootJarThe executable JAR name will consist of the name and the version of your project. For example, if you specified the following in your settings.gradle:
rootProject.name = 'myapp'and in your build.gradle:
group = 'com.company'
version = '0.0.1-SNAPSHOT'then the JAR name will be myapp-0.0.1-SNAPSHOT.jar.
The executable JAR file is created in the /build/libs folder. You can copy it anywhere and run as follows:
java -jar myapp-0.0.1-SNAPSHOT.jarIf you want to customize the packaging process or create a deployable WAR file, refer to the Spring Boot Documentation.
Creating Docker Image
Using Dockerfile
The most standard and reliable way of creating a Docker image is to use a Dockerfile. It works in any environment and can be adjusted for any requirements. The simplest Dockerfile is shown below:
FROM eclipse-temurin:21-jre-alpine
COPY build/libs/*.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]To build an image using a Dockerfile, do the following:
- 
Create a Dockerfile in the project root folder. 
- 
Build an executable JAR file as described in the previous section. 
- 
Build an image, executing the following command in the project root: docker build -t IMAGE_NAME .Replace IMAGE_NAMEwith your preferred image name.
Using bootBuildImage
The Gradle’s bootBuildImage task allows you to build an optimized image.
Open the terminal in the project root folder and execute the following command:
./gradlew -Pvaadin.productionMode=true bootBuildImagegradlew "-Pvaadin.productionMode=true" bootBuildImageBy default, the image will be created with the name of your project and tag which is equal to you project’s version.
For example, if you specified the following in your settings.gradle:
rootProject.name = 'myapp'and in your build.gradle:
group = 'com.company'
version = '0.0.1-SNAPSHOT'then the created image will be myapp:0.0.1-SNAPSHOT.
If you are using the Grid Export Actions add-on for exporting to Excel, you may need to add the following configuration to your build.gradle to make sure the image includes all required fonts:
tasks.named("bootBuildImage") {
    builder = "paketobuildpacks/builder-jammy-full"
}You can find more information on image generation and customization in the Spring Boot Documentation.
Deploying WAR
If you want to build a WAR file for deployment to an application server, follow these steps:
- 
Make sure your main application class extends SpringBootServletInitializer, for example:@SpringBootApplication public class MyApplication extends SpringBootServletInitializer implements AppShellConfigurator { // ... }
- 
Add the warplugin to thepluginssection of yourbuild.gradlefile:plugins { // ... id 'war' }
- 
Open the terminal in the project root folder and execute the following command: Linux and macOS./gradlew -Pvaadin.productionMode=true bootWarWindowsgradlew "-Pvaadin.productionMode=true" bootWar
The WAR file is created in the /build/libs folder. The file name is generated as described in the previous section.
| You need at least Tomcat 10 to run applications because since Jmix 2.0 they require support for Jakarta EE 9 ( Use the latest Tomcat 10 to deploy Jmix WAR. | 
Using JNDI Data Source
When deploying your application as a WAR, you can use a JNDI data source provided by the application server to externalize connection settings.
See below how to configure the main DataSource of your application for development and production environments using the Spring’s profiles feature.
- 
In your main application class, add @Profile("!prod")annotation todataSourcePropertiesanddataSourcemethods to make sure these beans are created only in development environment:@Profile("!prod") @Bean @Primary @ConfigurationProperties("main.datasource") DataSourceProperties dataSourceProperties() { return new DataSourceProperties(); } @Profile("!prod") @Bean @Primary @ConfigurationProperties("main.datasource.hikari") DataSource dataSource(DataSourceProperties dataSourceProperties) { return dataSourceProperties.initializeDataSourceBuilder().build(); }
- 
Add a method creating a DataSourcebean for the production environment:@Profile("prod") @Bean(name = "dataSource") @Primary DataSource prodDataSource(ApplicationContext context) { JndiDataSourceLookup lookup = new JndiDataSourceLookup(); DataSource dataSource = lookup.getDataSource("java:comp/env/jdbc/demo"); (1) // to avoid org.springframework.jmx.export.UnableToRegisterMBeanException: for (MBeanExporter mbeanExporter : context.getBeansOfType(MBeanExporter.class).values()) { if (JmxUtils.isMBean(((Object) dataSource).getClass())) { mbeanExporter.addExcludedBean("dataSource"); } } return dataSource; }1 JNDI name of the data source provided by the application server. 
- 
When running the application server, set active profile to prodinspring.profiles.activeapplication property.
Below is an example of configuring Tomcat for deploying a demo.war application.
- 
Copy demo.wartotomcat/webappsfolder.
- 
Create tomcat/bin/setenv.shfile with the following content:CATALINA_OPTS="-Dspring.profiles.active=prod"
- 
Create tomcat/conf/Catalina/localhost/demo.xmlfile defining the data source and set appropriate database connection parameters (XML file name must be the same as your WAR name):<Context> <Resource type="javax.sql.DataSource" name="jdbc/demo" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost/demo" username="root" password="root" maxIdle="2" maxTotal="20" maxWaitMillis="5000" /> </Context>Notice that the nameattribute of theResourceelement defines the JNDI name used in theJndiDataSourceLookup.getDataSource()method when creating theDataSourcebean.
- 
Copy an appropriate JDBC driver file (for example, postgresql-42.2.9.jar) totomcat/lib.
When you start Tomcat, the application will use the data source defined in the tomcat/conf/Catalina/localhost/demo.xml file.