BuildJar is generating jar that is not working

I generated Jar and run it before with simple app and it was working. Now in more complex app it is not. I am getting DataSourceLookupFailureException for main and also for secondary datasource. Aplication is running correctly if i run it via Cuba enviroment.

================================================================================================================================================================================================================================================
Some environment checks failed on core module:
Cannot find datasource for main data store
        org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'jdbc/CubaDS'; nested exception is javax.naming.NameNotFoundException: jdbc is not bound; remaining name 'jdbc/CubaDS'
================================================================================================================================================================================================================================================
15:00:30.930 INFO  c.h.c.c.s.p.PersistenceConfigProcessor  - Creating file /home/igisho/app-core/work/persistence.xml
15:00:30.955 INFO  c.h.c.c.s.p.PersistenceConfigProcessor  - Creating file /home/igisho/app-core/work/atena-persistence.xml
15:00:34.748 WARN  c.h.c.c.s.CubaCoreApplicationContext    - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodValidationPostProcessor' defined in class path resource [com/haulmont/cuba/spring.xml]: Cannot resolve reference to bean 'cuba_BeanValidation' while setting bean property 'beanValidation'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_BeanValidation': Unsatisfied dependency expressed through field 'messages'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_Messages': Unsatisfied dependency expressed through field 'messageTools'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_MessageTools': Unsatisfied dependency expressed through field 'metadata'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_Metadata': Unsatisfied dependency expressed through field 'tools'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_MetadataTools': Unsatisfied dependency expressed through field 'dynamicAttributesTools'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_DynamicAttributesTools': Unsatisfied dependency expressed through field 'dynamicAttributes'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_DynamicAttributesService': Unsatisfied dependency expressed through field 'dynamicAttributesManagerAPI'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_DynamicAttributesManager': Unsatisfied dependency expressed through field 'persistence'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_Persistence': Unsatisfied dependency expressed through field 'transactions'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cuba_Transactions': Unsatisfied dependency expressed through field 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [com/haulmont/cuba/spring.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/haulmont/cuba/spring.xml]: Cannot resolve reference to bean 'cubaDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource' defined in class path resource [com/haulmont/cuba/spring.xml]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'jdbc/CubaDS'; nested exception is javax.naming.NameNotFoundException: jdbc is not bound; remaining name 'jdbc/CubaDS'
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_atena' defined in class path resource [com/company/ramcovezmluvy/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc is not bound; remaining name 'jdbc/atena'
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_atena' defined in class path resource [com/company/ramcovezmluvy/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc is not bound; remaining name 'jdbc/atena'
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_atena' defined in class path resource [com/company/ramcovezmluvy/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc is not bound; remaining name 'jdbc/atena'
Related cause: org.springframework.beans.factor

Hi,
These errors mean that you have not configured database connection settings for your UberJAR application.
What CUBA platform version do you use?

Look to the documentation:
https://doc.cuba-platform.com/manual-7.2/uberjar_deployment.html
https://doc.cuba-platform.com/manual-7.2/build.gradle_buildUberJar.html

JNDI DataSource is usually defined in the jetty-env.xml file, which is specified either through coreJettyEnvPath parameter of the buildUberJar task. Or at runtime on target server with jettyEnvPath command line launch parameter.

CUBA 7.2 added new possibility: to use application-defined datasource.
With application-defined datasource you can specify all database connection parameters through application properties and forget about JNDI stuff.
See here:
https://doc.cuba-platform.com/manual-7.2/db_connection.html#db_connection_app

cuba.dataSourceProvider = application
cuba.dataSource.host = localhost
...

These application properties can be specified as appProperties parameter map for the buildUberJar task

When i switch to application defined datasource i get this:

C:\Users\igor.sovcik\StudioProjects\ramcove-zmluvy-fresh\build\distributions>java -jar uberJar\app.jar
Starting Jetty server on port: 8080 and contextPath: /app
LogbackConfigurator INFO Setting up CUBA default logging configuration
LogbackConfigurator INFO Could NOT find resource [C:\Users\igor.sovcik\StudioProjects\ramcove-zmluvy-fresh\build\distributions/logback.xml]
LogbackConfigurator INFO Found resource [jar:file:/C:/Users/igor.sovcik/StudioProjects/ramcove-zmluvy-fresh/build/distributions/uberJar/app.jar!/app-logback.xml]
09:18:50.572 INFO  org.eclipse.jetty.util.log              - Logging initialized @316ms to org.eclipse.jetty.util.log.Slf4jLog
09:18:50.744 INFO  org.eclipse.jetty.server.Server         - jetty-9.4.z-SNAPSHOT; built: 2019-06-10T16:30:51.723Z; git: afcf563148970e98786327af5e07c261fda175d3; jvm 1.8.0_241-b07
09:18:50.796 INFO  o.e.j.w.StandardDescriptorProcessor     - NO JSP Support for /app-core, did not find org.eclipse.jetty.jsp.JettyJspServlet
09:18:50.826 INFO  org.eclipse.jetty.server.session        - DefaultSessionIdManager workerName=node0
09:18:50.826 INFO  org.eclipse.jetty.server.session        - No SessionScavenger set, using defaults
09:18:50.831 INFO  org.eclipse.jetty.server.session        - node0 Scavenging every 660000ms
09:18:50.952 INFO  c.h.cuba.core.sys.AppComponents         - Using app components: [com.haulmont.cuba, com.haulmont.reports, com.haulmont.addon.grapesjs, com.haulmont.addon.emailtemplates]
09:18:50.985 INFO  c.h.c.c.s.AbstractWebAppContextLoader   - Loading app properties from classpath:com/company/ramcovezmluvy/app.properties
09:18:50.987 INFO  c.h.c.c.s.AbstractWebAppContextLoader   - Loading app properties from /WEB-INF/local.app.properties
09:18:51.037 INFO  c.h.cuba.core.sys.AppContextLoader      - DbmsType of the main database is set to mysql
09:18:51.062 INFO  c.h.c.c.s.e.DataStoresCheck             - Checking connection to data store Main
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
09:18:51.248 INFO  c.h.c.c.s.e.EnvironmentChecksRunner     - Environment checks on core module completed successfully
09:18:51.393 INFO  c.h.c.c.s.p.PersistenceConfigProcessor  - Creating file C:\Users\igor.sovcik\StudioProjects\ramcove-zmluvy-fresh\build\distributions\app-core\work\persistence.xml
09:18:51.411 INFO  c.h.c.c.s.p.PersistenceConfigProcessor  - Creating file C:\Users\igor.sovcik\StudioProjects\ramcove-zmluvy-fresh\build\distributions\app-core\work\atena-persistence.xml
09:18:53.948 INFO  com.zaxxer.hikari.HikariDataSource      - Connection Pool-Main - Starting...
09:18:53.954 WARN  c.z.hikari.util.DriverDataSource        - Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
09:18:54.007 INFO  com.zaxxer.hikari.HikariDataSource      - Connection Pool-Main - Start completed.
09:18:54.931 WARN  c.h.c.c.s.CubaCoreApplicationContext    - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory_atena' defined in class path resource [com/company/ramcovezmluvy/spring.xml]: Cannot resolve reference to bean 'cubaDataSource_atena' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_atena' defined in class path resource [com/company/ramcovezmluvy/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc is not bound; remaining name 'jdbc/atena'
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_atena' defined in class path resource [com/company/ramcovezmluvy/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc is not bound; remaining name 'jdbc/atena'
09:18:54.935 INFO  com.zaxxer.hikari.HikariDataSource      - Connection Pool-Main - Shutdown initiated...
09:18:54.948 INFO  com.zaxxer.hikari.HikariDataSource      - Connection Pool-Main - Shutdown completed.
09:18:54.955 ERROR c.h.c.c.s.AbstractWebAppContextLoader   - Error initializing application
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory_atena' defined in class path resource [com/company/ramcovezmluvy/spring.xml]: Cannot resolve reference to bean 'cubaDataSource_atena' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cubaDataSource_atena' defined in class path resource [com/company/ramcovezmluvy/spring.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jdbc is not bound; remaining name 'jdbc/atena'
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:342) ~[shared/:na]
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) ~[shared/:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1699) ~[shared/:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1444) ~[shared/:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[shared/:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[shared/:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[shared/:na]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[shared/:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[shared/:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[shared/:na]

Now when i switch back to jndi i get different error:

C:\Users\igor.sovcik\StudioProjects\ramcove-zmluvy-fresh\build\distributions>java -jar uberJar\app.jar
Starting Jetty server on port: 8080 and contextPath: /app
LogbackConfigurator INFO Setting up CUBA default logging configuration
LogbackConfigurator INFO Could NOT find resource [C:\Users\igor.sovcik\StudioProjects\ramcove-zmluvy-fresh\build\distributions/logback.xml]
LogbackConfigurator INFO Found resource [jar:file:/C:/Users/igor.sovcik/StudioProjects/ramcove-zmluvy-fresh/build/distributions/uberJar/app.jar!/app-logback.xml]
09:27:47.692 INFO  org.eclipse.jetty.util.log              - Logging initialized @310ms to org.eclipse.jetty.util.log.Slf4jLog
09:27:47.861 INFO  org.eclipse.jetty.server.Server         - jetty-9.4.z-SNAPSHOT; built: 2019-06-10T16:30:51.723Z; git: afcf563148970e98786327af5e07c261fda175d3; jvm 1.8.0_241-b07
09:27:47.946 INFO  o.e.j.w.StandardDescriptorProcessor     - NO JSP Support for /app-core, did not find org.eclipse.jetty.jsp.JettyJspServlet
09:27:47.968 INFO  org.eclipse.jetty.server.session        - DefaultSessionIdManager workerName=node0
09:27:47.968 INFO  org.eclipse.jetty.server.session        - No SessionScavenger set, using defaults
09:27:47.970 INFO  org.eclipse.jetty.server.session        - node0 Scavenging every 600000ms
09:27:48.097 INFO  c.h.cuba.core.sys.AppComponents         - Using app components: [com.haulmont.cuba, com.haulmont.reports, com.haulmont.addon.grapesjs, com.haulmont.addon.emailtemplates]
09:27:48.128 INFO  c.h.c.c.s.AbstractWebAppContextLoader   - Loading app properties from classpath:com/company/ramcovezmluvy/app.properties
09:27:48.130 INFO  c.h.c.c.s.AbstractWebAppContextLoader   - Loading app properties from /WEB-INF/local.app.properties
09:27:48.175 INFO  c.h.cuba.core.sys.AppContextLoader      - DbmsType of the main database is set to mysql
09:27:48.193 INFO  c.h.c.c.s.e.DataStoresCheck             - Checking connection to data store Main
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
09:27:48.269 WARN  c.h.c.c.s.e.EnvironmentChecksRunner     -
====================================================================================================================================================================================================================================================================================================
Some environment checks failed on core module:
Exception occurred while connecting to data store _MAIN_
        java.sql.SQLException: Cannot create PoolableConnectionFactory (Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';allowMultiQueries=true&serverTimezone=UTC'.)
====================================================================================================================================================================================================================================================================================================
09:27:48.364 INFO  c.h.c.c.s.p.PersistenceConfigProcessor  - Creating file C:\Users\igor.sovcik\StudioProjects\ramcove-zmluvy-fresh\build\distributions\app-core\work\persistence.xml
09:27:48.381 INFO  c.h.c.c.s.p.PersistenceConfigProcessor  - Creating file C:\Users\igor.sovcik\StudioProjects\ramcove-zmluvy-fresh\build\distributions\app-core\work\atena-persistence.xml
09:27:52.794 INFO  c.h.c.c.s.CubaThreadPoolTaskScheduler   - Initializing ExecutorService 'scheduler'
09:27:53.319 INFO  c.h.cuba.core.sys.jmx.MBeanExporter     - Registering beans for JMX exposure: [app-core.cuba:type=PersistenceManager, app-core.cuba:type=ConfigStorage, app-core.cuba:type=UserSessions, app-core.cuba:type=UniqueNumbers, app-core.cuba:type=Emailer, app-core.cuba:type=EntityLog, app-core.cuba:type=FileStorage, app-core.cuba:type=LockManager, app-core.cuba:type=CachingFacade, app-core.cuba:type=ClusterManager, app-core.cuba:type=ScriptingManager, app-core.cuba:type=ServerInfo, app-core.cuba:type=Scheduling, app-core.cuba:type=PasswordEncryptionSupport, app-core.cuba:type=JmxNodeIdentifier, app-core.cuba:type=JmxLogControl, app-core.cuba:type=ClassLoaderManager, app-core.cuba:type=StatisticsCounter, app-core.cuba:type=BruteForceProtection, app-core.cuba:type=QueryCacheSupport]
09:27:53.430 INFO  c.h.cuba.core.sys.jmx.MBeanExporter     - Registering beans for JMX exposure: [app-core.reports:type=CubaOfficeIntegration, app-core.reports:type=ReportImportExport, app-core.reports:type=ReportingMigrator]
09:27:56.444 INFO  c.h.cuba.core.sys.MetadataImpl          - Initializing metadata
09:27:56.650 INFO  c.h.cuba.core.sys.MetadataImpl          - Metadata initialized in 205 ms
09:27:57.739 ERROR c.h.c.c.s.AbstractWebAppContextLoader   - Error initializing application
java.lang.RuntimeException:
=======================================================================================
ERROR: Cannot check and update data store [Main]. See the stacktrace below for details.
=======================================================================================
        at com.haulmont.cuba.core.sys.dbupdate.DbUpdateManager.updateDatabase(DbUpdateManager.java:78) ~[classes/:na]
        at com.haulmont.cuba.core.sys.dbupdate.DbUpdateManager.applicationInitialized(DbUpdateManager.java:61) ~[classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_241]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_241]

i am using latest version of cuba

regarding that malformed database URL cant see any problem with it:

<Set name="url"><![CDATA[jdbc:mysql://some-ip-address/some-schema?useSSL=false&amp;allowMultiQueries=true&amp;serverTimezone=UTC]]></Set>

Ok, i found the solution. Cuba IDE is ormating connection string where it adds & exept of & into CDATA declaration.

Hmm, this is a bug.
Created a Studio ticket: https://youtrack.cuba-platform.com/issue/STUDIO-8130