wildfly-jar-maven-plugin
wildfly-jar-maven-plugin copied to clipboard
Externalize configurations Example
How to externalize configurations? Like for example, in persistence.xml, I need to set the jndi data source name and hibernate.hbm2ddl.auto differently in my local, staging and prod.
@hendratommy , is it something that you are already achieving with WildFly (without using bootable JAR)?
It would be interesting to see how you are doing it. If that is based on custom JBoss modules (as we can see there: https://www.java2novice.com/jboss/external-property-in-classpath/), that is something that you could mimic with bootable JAR by defining different maven profiles and using the capability to copy extra content inside a bootable JAR.
Perhaps a simpler solution would be to have each maven profile to contain resources configured differently. So, for example, a different persistence.xml file per profile.
@jfdenise No, I haven't done it yet. I was thinking to use environment variable since the datasource layer is also use environment variable. Looking at this link seems like this feasible in standard WildFly.
That seems interesting, please keep us posted with your result. We could then create a new example to cover your use-case. Thank-you.
Hi,
It's working, I made small POC using bootable JAR to configure persistence.xml
to use environment variables by adding ee
layer and use cli
to configure it.
Here is the repo hendratommy/wf-articles.
However it is not what I'm expecting when working bootable jar
, I was expecting something similar to Spring Boot
.
@hendratommy , thank-you, could you point me to the workflow/approach you would have preferred? Thank-you.
I think Spring-Boot
configuration is great way to configure our application. Our configuration basically all reside in single file src/main/resources/application.yml
which we can fill with default values. These configuration value is overridable at runtime either by supplying environment variables or by putting config/application.yml
in the same folder with the jar
file. And we can also have el
expression inside the config explicitly to lookup the values.
@hendratommy , thank-you. I added your use-case to the JIRA that tracks support for yaml config: https://issues.redhat.com/browse/WFLY-13978
Currently I do this with maven profiles and then resource filtering
Maven Profile
<profile>
<id>sandbox</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<applicationMode>SANDBOX</applicationMode>
<applicationVersion>${project.version}</applicationVersion>
<applicationRootPath>/var/sandbox/</applicationRootPath>
<datasource_JNDI_Name>java:jboss/datasources/PORTAL_DS</datasource_JNDI_Name>
<hibernate.dialect>MySQL57InnoDB</hibernate.dialect>
<hibernate.ddl_mode>create</hibernate.ddl_mode>
</properties>
</profile>
Persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1">
<persistence-unit name="primary" transaction-type="JTA">
<jta-data-source>${datasource_JNDI_Name}</jta-data-source>
<properties>
<property name="hibernate.dialect" value="${hibernate.dialect}"/>
<property name="hibernate.hbm2ddl.auto" value="${hibernate.ddl_mode}"/>
</properties>
</persistence-unit>
</persistence>
@codylerum @hendratommy , FYI, using WF23 you can excute CLI script to adjust your configuration at runtime. We have an example that has been evolved to showcase the feature: https://github.com/wildfly-extras/wildfly-jar-maven-plugin/tree/master/examples/authentication It could open new possibilities in your context.