I have an application that needs to support both native deployments and as a Docker container where the database connection properties are supplied through a config file. And of course, I also need to support development with direct deployment to the IDE’s registered Payara server (and through Docker/Skaffold in the future - things are in flux, hence the duality).
I already have WAR services built as Docker Payara Micro images where WEB-INF/payara-resources.xml
registers a jdbc resource (java:app/jdbc/MyPU
), and I want to do something similar with an EAR and Payara Full, but it needs work as both a native deployment and Docker image. The only roadblock I’m having is the EAR’s META-INF/payara-resources.xml
not recognizing the environment (not system) variables.
my-app.ear/META-INF/payara-resources.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Payara.fish//DTD Payara Server 4 Resource Definitions//EN" "https://raw.githubusercontent.com/payara/Payara-Server-Documentation/master/schemas/payara-resources_1_6.dtd">
<resources>
<jdbc-resource pool-name="MYDB" jndi-name="jdbc/MyPU" enabled="true" ></jdbc-resource>
<jdbc-connection-pool datasource-classname="com.microsoft.sqlserver.jdbc.SQLServerDataSource"
name="MYDB"
res-type="javax.sql.DataSource"
is-connection-validation-required="true"
connection-validation-method="table"
validation-table-name="sys.tables"
fail-all-connections="true">
<property name="User" value="${ENV=DATABASE_USER}"></property>
<property name="Password" value="${ENV=DATABASE_PASS}"></property>
<property name="DatabaseName" value="${ENV=DATABASE_NAME}"></property>
<property name="ServerName" value="${ENV=DATABASE_SERVER}"></property>
<property name="PortNumber" value="${ENV=DATABASE_SERVER_PORT}"></property>
<property name="Encrypt" value="${ENV=DATABASE_SERVER_ENCRYPT}"></property>
</jdbc-connection-pool>
</resources>
From the IDE (Netbeans) deploying directly to Payara:
Here is nbactions.xml
, which just configures the launch (this works with the Payara Micro services that use the Maven PM plugin). Notice I tried both with Env.
and without:
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>war</packaging>
<packaging>ear</packaging>
<packaging>ejb</packaging>
</packagings>
<goals>
<goal>package</goal>
</goals>
<properties>
<netbeans.deploy>true</netbeans.deploy>
<Env.DATABASE_USER>user</Env.DATABASE_USER>
<Env.DATABASE_PASS>pass</Env.DATABASE_PASS>
<Env.DATABASE_NAME>MyDB</Env.DATABASE_NAME>
<Env.DATABASE_SERVER>server</Env.DATABASE_SERVER>
<Env.DATABASE_SERVER_PORT>1433</Env.DATABASE_SERVER_PORT>
<DATABASE_USER>user</DATABASE_USER>
<DATABASE_PASS>pass</DATABASE_PASS>
<DATABASE_NAME>MyDB</DATABASE_NAME>
<DATABASE_SERVER>server</DATABASE_SERVER>
<DATABASE_SERVER_PORT>1433</DATABASE_SERVER_PORT>
</properties>
</action>
</actions>
cd app; DATABASE_USER=user DATABASE_PASS=pass DATABASE_NAME=MyDB DATABASE_SERVER=server DATABASE_SERVER_PORT=1433 JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 mvn -Dnetbeans.deploy=true -DDATABASE_USER=user -DDATABASE_PASS=pass -DDATABASE_NAME=MyDB -DDATABASE_SERVER=server -DDATABASE_SERVER_PORT=1433 -Dexec.vmArgs= -Dexec.appArgs= --update-snapshots -U -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true -Dmaven.resolver.transport=wagon package
Error:
SEVERE: RAR5104 : Not a valid type for this method : ${ENV=DATABASE_SERVER_PORT}
WARNING: RAR5038:Unexpected exception while creating resource for pool { PoolInfo : (name=java:app/MYDB), (applicationName=my-app) }. Exception : javax.resource.ResourceException: Parameter wrong for this method : ${ENV=DATABASE_SERVER_PORT}
WARNING: RAR5117 : Failed to obtain/create connection from connection pool [ { PoolInfo : (name=java:app/MYDB), (applicationName=my-app) } ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Parameter wrong for this method : ${ENV=DATABASE_SERVER_PORT}
WARNING: RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Parameter wrong for this method : ${ENV=DATABASE_SERVER_PORT}]
SEVERE: Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.11.payara-p1): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Parameter wrong for this method : ${ENV=DATABASE_SERVER_PORT}
In addition, when attempting to run the Docker container I get the following error:
{0} is not a valid data source. If you are using variable replacement then ensure that is available on the DAS
Exception while preparing the app : Invalid resource : jdbc/MyPU__pm
app-stack_app-service.1.6kbdpgk3gfrw@machien | com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : jdbc/MyPU__pm
So, it seems as though the environment variables are ignored.