Hello Everyone,
I have recently migrated from hsql to postgres for my cuba reports application. Here are the DB connection settings in my build.gradle file
Migrating to postgres was successfully done.
Here the details are hard coded in builde.gradle file, but now I’m having a multiple environment where these details will differ. Right now I have to change in build.gradle and build it again to execute for environment specific. Instead I want these data to be dynamic so I don’t have to change the details and build for each environment. I thought of reading it from properties file but build.gradle is used during build time itself and properties file will be available on server for environment specific. So reading from properties file in build.gradle is not making sense to(I might be wrong please correct me here).
Can someone please help me or share some example to achieve this?
Also I have a context.xml file where I need to define the DataSource and the DB credentials. Those needs to be removed from the code and read dynamically as well
If you store you database connection parameters in app.properties, then in other environments you can override them using OS environment variables or using local.app.properties file.
see Application Properties - CUBA Platform. Developer’s Manual
If you keep database connection settings in the context.xml file - then you can just change the contents of the context.xml file in the corresponding environment.
Well, then you can use the last link and parameterize Tomcat’s context.xml file by assigning Java system properties in setenv.sh script (or systemd service file).
Thanks for the response, Alexander. I understood that the values for context.xml can be configured from java system properties. But in case of having those credentials in build.gradle file, Does the below approach work here?
Values from build.gradle file refer only to development environment, they are not related to the runtime environment.
If you want to have build-time properties to depend on environment variables, it is totally possible in Gradle, which allows to call arbitrary Java APIs from the build script.
Thanks Alexander.
After migrating to postgres from hsql, When trying to deploy the app in the runtime environment, I am getting the below error
Caused by: java.lang.ClassNotFoundException: org.hsqldb.jdbc.JDBCDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131]
at com.haulmont.cuba.core.sys.CubaSingleAppClassLoader.loadClass(CubaSingleAppClassLoader.java:52) ~[cuba-shared-lib-6.5.7.jar:6.5.7]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131]
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2136) ~[tomcat-dbcp.jar:8.5.20]
... 27 common frames omitted
When I grep in my tomcat folder for hsql entries, I found there is a file called cuba-reports.xml (./conf/Catalina/localhost/cuba-reports.xml) which has the below entries
How does this cuba-reports.xml file gets generated? and how does it populate the values? Is there a way to fix it?