Tomcat deployment problem

FlowUI project deployment testing

I have tried to deploy my project to an external server instead of my development server and it is failed. My application was running in 1.4 in a remote server but the file size was unexpectedly huge over 600MB. Now the same project war file is only about 110BM but it’s no more running on the remote server. Let me explain what is happening:

Development server setup
My IDE is running in my local computer but I am using the MS SQL server in a remote server using a public IP, for example, IP address e.g. 43.111.11.11

The application name is “test” and database name is “testdb”

The data source name in (JNDI) is as follows and the mainApplication file is updated as suggested in the user manual (as you can see as attached):

DataSource dataSource = lookup.getDataSource("java:comp/env/jdbc/testdb");

I have built the war file for ‘prod’ using the following command:

./gradlew -Pvaadin.productionMode=true bootWar

Server deployment configuration
This server is the same remote server that my database is located I accessed in development environment using the IP address (e.g. 43.111.11.11). That means, when deployed, the war file should read from localhost instead of through that public IP. Note that my CUBA application is running here which indicates that tomcat is Ok.

Here is my context file that I have saved in the folder Tomcat9/conf/Catalina/localhost/

Also created tomcat/bin/setenv.sh file with the following content:

CATALINA_OPTS="-Dspring.profiles.active=prod"

The war file (test.war) is then deployed, no!! not working.

here is the log file extract from tomcat

03-Mar-2023 11:49:35.812 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.44]
03-Mar-2023 11:49:35.843 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\Catalina\localhost\test.xml]
03-Mar-2023 11:49:47.155 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
03-Mar-2023 11:49:47.421 SEVERE [main] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
03-Mar-2023 11:49:47.437 SEVERE [main] org.apache.catalina.core.StandardContext.startInternal Context [/test] startup failed due to previous errors
03-Mar-2023 11:49:47.515 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\Catalina\localhost\test.xml] has finished in [11,672] ms
03-Mar-2023 11:49:47.515 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\docs]
03-Mar-2023 11:49:47.562 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\docs] has finished in [47] ms
03-Mar-2023 11:49:47.562 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\manager]
03-Mar-2023 11:49:47.624 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\manager] has finished in [62] ms
03-Mar-2023 11:49:47.640 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\ROOT]
03-Mar-2023 11:49:47.655 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\ROOT] has finished in [15] ms
03-Mar-2023 11:49:47.671 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
03-Mar-2023 11:49:47.687 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [11951] milliseconds
03-Mar-2023 11:53:05.141 INFO [Thread-4] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
03-Mar-2023 11:53:05.165 INFO [Thread-4] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
03-Mar-2023 11:53:05.196 INFO [Thread-4] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
03-Mar-2023 11:53:05.212 INFO [Thread-4] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]

2023-03-03 11:53:06 Apache Commons Daemon procrun stderr initialized.
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/9.0.44
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Mar 4 2021 21:49:34 UTC
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.44.0
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows Server 2016
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\AdoptOpenJDK\jdk-11
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           11.0.10+9
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            AdoptOpenJDK
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Program Files\Apache Software Foundation\Tomcat 9.0
03-Mar-2023 11:53:07.602 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 9.0
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Program Files\Apache Software Foundation\Tomcat 9.0
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\logging.properties
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dfile.encoding=UTF-8
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: exit
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: abort
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms128m
03-Mar-2023 11:53:07.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx4096m
03-Mar-2023 11:53:07.634 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [C:\Program Files\Apache Software Foundation\Tomcat 9.0\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\AdoptOpenJDK\jdk-11\bin;C:\Program Files\AdoptOpenJDK\jdk-11.0.10.9-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\ESET\ESET Security\;C:\Windows\ServiceProfiles\LocalService\AppData\Local\Microsoft\WindowsApps;.]
03-Mar-2023 11:53:08.212 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
03-Mar-2023 11:53:08.352 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [1087] milliseconds
03-Mar-2023 11:53:08.446 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
03-Mar-2023 11:53:08.446 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.44]
03-Mar-2023 11:53:08.493 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\Catalina\localhost\test.xml]
03-Mar-2023 11:53:20.056 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
03-Mar-2023 11:53:20.306 SEVERE [main] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
03-Mar-2023 11:53:20.337 SEVERE [main] org.apache.catalina.core.StandardContext.startInternal Context [/test] startup failed due to previous errors
03-Mar-2023 11:53:20.399 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\Catalina\localhost\test.xml] has finished in [11,906] ms
03-Mar-2023 11:53:20.399 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\docs]
03-Mar-2023 11:53:20.446 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\docs] has finished in [47] ms
03-Mar-2023 11:53:20.446 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\manager]
03-Mar-2023 11:53:20.509 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\manager] has finished in [63] ms
03-Mar-2023 11:53:20.509 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\ROOT]
03-Mar-2023 11:53:20.540 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\ROOT] has finished in [31] ms
03-Mar-2023 11:53:20.540 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
03-Mar-2023 11:53:20.556 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [12198] milliseconds

note that, my development environment is using jdk17 whereas the server has jdk11, can this be an issue?

I have attached the test project, in case you need it. Thank you in advance for your help.
test.zip (384.3 KB)

Yes, most probably it’s the cause. Production JDK must be the same or newer than the development JDK.

Hi Konstantin
I have uninstalled JDK11 and now using JDK17 where i am trying to deploy, now JDK is the exact same version of my development environment. Here is the tomcat log where you will see tomcat is registered with JDK17.
test app-tomcat log.txt (27.3 KB)

As you see the application is still trying to connect to the database by using the public IP address I used to connect to the remote database from my local machine in dev env (as follows) which is in application.properties.

main.datasource.url = jdbc:sqlserver://41.111.111.11;databaseName=testdb;encrypt=false
main.datasource.username = sa
main.datasource.password =xxxxxx

That means, the application is not using JNDI datasource through you will see the JNDI usage recommendation is followed even I have build the war file for “prod”.

text.xml file stored (as below) sometimes found that the system has removed it surprisingly. But it still doesn’t work when the test.xml file is not removed.

<Context>
    <Resource type="javax.sql.DataSource"
              name="jdbc/test"
              driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
              url="jdbc:sqlserver://localhost;databaseName=testdb;encrypt=true;trustServerCertificate=true"
              username="sa"
              password="*******"
              maxIdle="2"
              maxTotal="20"
              maxWaitMillis="5000"
    />
</Context>

and JNDI reference in main application:

 //For Production environment
    @Profile("prod")
    @Bean(name = "dataSource")
    @Primary
    DataSource prodDataSource(ApplicationContext context) {
        JndiDataSourceLookup lookup = new JndiDataSourceLookup();
        DataSource dataSource = lookup.getDataSource("java:comp/env/jdbc/test");

        // 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;
    }

Additional inputs:
As a last resort when I changed the server IP address from 41.111… to localhost in the application.properties file before building the war file, it worked. This clearly confirms that the application is not using the JNDI connection parameters. If I had my local database in the dev environment then I could never notice this issue but in a production environment where generally database and applications are deployed in two different servers for this architecture, it’s still a big problem. Most-likely a bug or I made a mistake somewhere in properly configuring the usage of JNDI. Thanks for any solutions.

Thanks for any help.

Hi Mortoza,

Looks like you are deploying on Windows, so obviously you need to create a setenv.bat file instead of *.sh. Also, if you are using a Windows Service to run Tomcat, you should specify all Java options in the service configuration as for a CUBA application, see WAR deployment to Tomcat Windows Service - CUBA Platform. Developer’s Manual, item 5 and below.

Hi Konstantin,
Oh, that’s right I have to use setenv.bat instead of .sh
I already did the config for Java options in tomcat, so will try with setenv.bat and hope it will work

Thank you.

May be worth updating user manuals for those small things… and of course for new users in Jmix, java config in Tomcat will be helpful for them…