The examples below refer to TomEE 10 and SAP Java Buildpack 2.
-
Create a
resources.xml
file.-
If the data source is to be used from a Web application, you have to create the file inside the
WEB-INF/
directory. -
If the data source is to be used from Enterprise JavaBeans (EJBs), you have to create the file inside the
META-INF/
directory.
The
resources.xml
file has to be inside the application's WAR file, and has to contain information about the data source to be used.resources.xml
<?xml version='1.0' encoding='utf-8'?> <resources> <Resource id="jdbc/DefaultDB" provider="xs.openejb:XS Default JDBC Database" type="javax.sql.DataSource" > service=${service_name_for_DefaultDB} </Resource> </resources>
-
-
Add the default keys and their values. You need to include the data source information in directory
META-INF/sap_java_buildpack/config/resource_configuration.yml
of the WAR file.-
Define a default service name for a Web application:
resource_configuration.yml
--- tomee/webapps/ROOT/WEB-INF/resources.xml: service_name_for_DefaultDB: di-core-hdi
-
Define a default service name for an EJB:
resource_configuration.yml
--- tomee/webapps/ROOT/META-INF/resources.xml: service_name_for_DefaultDB: di-core-hdi
-
-
Add the key values to be updated. You need to include the data source information to be updated in the
manifest.yml
file.-
Define the new service name for the look-up of the data source in a Web application:
manifest.yml
env: TARGET_RUNTIME: tomee JBP_CONFIG_RESOURCE_CONFIGURATION: "['tomee/webapps/ROOT/WEB-INF/resources.xml': {'service_name_for_DefaultDB' : 'my-local-di-core-hdi'}]"
-
Define the new service name for the look-up of the data source in an EJB:
manifest.yml
env: TARGET_RUNTIME: tomee JBP_CONFIG_RESOURCE_CONFIGURATION: "['tomee/webapps/ROOT/META-INF/resources.xml':{'service_name_for_DefaultDB' : 'my-local-di-core-hdi'}]"
-
As a result of this configuration, when the application starts, the com.sap.xs.jdbc.datasource.TomEEDataSourceFactory factory takes the parameters bound to the my-local-di-core-hdi service from the environment, creates a data source, and binds it under jdbc/DefaultDB
. The application then uses the Java Naming and Directory Interface (JNDI) to look up how to connect with the database.
Related Information