{"id":741,"date":"2021-04-10T11:14:28","date_gmt":"2021-04-10T09:14:28","guid":{"rendered":"http:\/\/h2916922.stratoserver.net:8084\/?p=741"},"modified":"2021-04-10T11:14:29","modified_gmt":"2021-04-10T09:14:29","slug":"configuring-mariadb-datasources-in-wildfly","status":"publish","type":"post","link":"https:\/\/www.ivojonker.nl\/?p=741","title":{"rendered":"Configuring Mariadb datasources in wildfly"},"content":{"rendered":"\n<p>While i had been using glassfish\/payara for most of my projects, i decided to switch to Wildfly for a project in which i preferred to have ActiveMQ als a JMS provider.<\/p>\n\n\n\n<p>Using the JBOSS_CLI to create the JMS configurations was quite easy, but i did have a small challenge in figuring out how to create the mariadb driver\/(xa)datasource.<\/p>\n\n\n\n<p>This is what i ended up using:<\/p>\n\n\n\n<p class=\"has-medium-font-size\">1. Configure-buildTime.sh &#8211; a script that i run during docker build<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Download the maria-db driver\ncurl https:\/\/downloads.mariadb.com\/Connectors\/java\/connector-java-2.7.2\/mariadb-java-client-2.7.2.jar > \/opt\/jboss\/mariadb.driver.jar\n# Execute the client script that will register the driver &amp; datasources\n$JBOSS_CLI --file=\/opt\/jboss\/wildfly\/jdbc.command.cli\r\n<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">2. jdbc.command.cli &#8211; the JBOSS_CLI script that registers the driver and datasources.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>connect\r\nbatch\r\n\r\nmodule add \\\r\n --name=org.mariadb \\\r\n --dependencies=javax.api,javax.transaction.api \\\r\n --resources=\/opt\/jboss\/mariadb.driver.jar \\\r\n\r\n\/subsystem=datasources\/jdbc-driver=mariadb:add(driver-name=\"mariadb\", driver-module-name=\"org.mariadb\", driver-class-name=\"org.mariadb.jdbc.Driver\", driver-xa-datasource-class-name=\"org.mariadb.jdbc.MariaDbDataSource\")\r\n\r\ndata-source add \\\r\n --name=MyDatasource \\\r\n --jndi-name=java:\/jdbc\/MyDatasource \\\r\n --driver-name=mariadb \\\r\n --connection-url=jdbc:mysql:\/\/${env.RDS_HOSTNAME:${env.RDS_HOSTNAME}}:${env.RDS_PORT:${env.RDS_PORT}}\/${env.RDS_DB_NAME:${env.RDS_DB_NAME}} \\\r\n --user-name=${env.RDS_USERNAME:${env.RDS_USERNAME}} \\\r\n --password=${env.RDS_PASSWORD:${env.RDS_PASSWORD}} \\\r\n --check-valid-connection-sql=\"\/* ping *\/ SELECT 1\"\r\n\r\nxa-data-source add --name=MyDatasourceXA \\\r\n --driver-name=mariadb \\\r\n --jndi-name=java:\/jdbc\/MyDatasourceXA \\\r\n --user-name=${env.RDS_USERNAME:${env.RDS_USERNAME}} \\\r\n --password=${env.RDS_PASSWORD:${env.RDS_PASSWORD}} \\\r\n --recovery-username=${env.RDS_USERNAME:${env.RDS_USERNAME}} \\\r\n --recovery-password=${env.RDS_PASSWORD:${env.RDS_PASSWORD}} \\\r\n --xa-datasource-properties=Url=jdbc:mysql:\/\/${env.RDS_HOSTNAME:${env.RDS_HOSTNAME}}:${env.RDS_PORT:${env.RDS_PORT}}\/${env.RDS_DB_NAME:${env.RDS_DB_NAME}} \\ \r\n --xa-datasource-class=org.mariadb.jdbc.MariaDbDataSource\\\r\n --check-valid-connection-sql=\"\/* ping *\/ SELECT 1\"\r\n\r\nrun-batch\r\n\r\nexit<\/code><\/pre>\n\n\n\n<p>Notice how i give my parameters a default value recursing to the parameter itself. This is done because the JBOSS_CLI  apparantly tries to expand the values (although default configured not to do so version 21.0.1), and i could not find another way to prevent this &#8211; it feels like a bug. My goal was to have the parameters to be resolved at image-runtime &#8211; and that worked!<\/p>\n\n\n\n<p>3. My war\/META-INF\/persistence.xml  <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>..\n&lt;jta-data-source>jdbc\/MyDatasourceXA&lt;\/jta-data-source>\n..<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While i had been using glassfish\/payara for most of my projects, i decided to switch to Wildfly for a project in which i preferred to have ActiveMQ als a JMS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-741","post","type-post","status-publish","format-standard","hentry","category-geen-categorie"],"_links":{"self":[{"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/posts\/741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=741"}],"version-history":[{"count":1,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/posts\/741\/revisions"}],"predecessor-version":[{"id":742,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/posts\/741\/revisions\/742"}],"wp:attachment":[{"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}