Skip to content

Instantly share code, notes, and snippets.

@jmesnil
Last active April 2, 2024 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmesnil/60384821d3c869a813c51c03ccb0cead to your computer and use it in GitHub Desktop.
Save jmesnil/60384821d3c869a813c51c03ccb0cead to your computer and use it in GitHub Desktop.
WildFly with Oracle JDBC driver
$ ls .
Dockerfile      module.xml      ojdbc11.jar

$ cat module.xml

<module xmlns="urn:jboss:module:1.9" name="com.oracle">
    <resources>
      <resource-root path="ojdbc11.jar"/>
    </resources>
    <dependencies>
      <module name="javax.api"/>
      <module name="javax.transaction.api"/>
    </dependencies>
  </module>

$ cat Dockerfile

FROM quay.io/wildfly/wildfly:28.0.1.Final-jdk17

COPY module.xml $JBOSS_HOME/modules/com/oracle/main/
COPY ojdbc11.jar $JBOSS_HOME/modules/com/oracle/main/

$ docker build -t wildfly-with-oracle .
$ docker run -p 8080:8080 wildfly-with-oracle:latest

For the next command, replace d437c231ccf9 with your own container ID (from docker ps)

$ docker exec -it d437c231ccf9 /opt/jboss/wildfly/bin/jboss-cli.sh -c

[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=com.oracle)
{"outcome" => "success"}

In the logs from WildFly, you will see:

09:29:57,135 INFO  [org.jboss.as.connector.subsystems.datasources] (management-handler-thread - 1) WFLYJCA0004: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 23.3)
09:29:57,135 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0018: Started Driver service with driver-name = oracle

=> that shows tha the oracle driver was properly created from the com.oracle JBoss Module

@jreed-cartago
Copy link

Ok so I've double checked my module.xml to ensure it looks like the one you've posted above.

<?xml version="1.0" ?>
<module xmlns="urn:joss:module:1.9" name="com.oracle">
  <resources>
    <resource-root path="ojdbc11.jar" />
  </resources>
  <dependencies>
    <module name="javax.api" />
    <module name="javax.transaction.api" />
  </dependencies>
</module>

As I mentioned over on mastadon I was originally using a ojdbc8.jar which I thought might have been a problem but I've corrected this.

I also made sure my dockerfile was correct as per your example above.

FROM quay.io/wildfly/wildfly:28.0.1.Final-jdk17

COPY module.xml /opt/jboss/wildfly/modules/com/oracle/main/
COPY ojdbc11.jar /opt/jboss/wildfly/modules/com/oracle/main/

Now here is the difference between your implementation and mine. I'm using a docker-compose.yml file as I wanted to handle the port and volumes. In particular for configuration of the standalone.xml. So under the datasources subsystem I've added in the following entry under drivers

<driver name="oracle" module="com.oracle">
   <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>

And I've also added a datasource element that uses the driver oracle, with the correct connection url, and security information.

Is there something I'm missing here?

@jmesnil
Copy link
Author

jmesnil commented Mar 21, 2024

@jreed-cartago Mmh, I'm not sure what your issue is about.
Your XML code snippet looks correct and is what I get when I add the driver with the CLI:

/subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=com.oracle, driver-class-name=oracle.jdbc.driver.OracleDriver)
{"outcome" => "success"}

=>

<drivers>
  <driver name="oracle" module="com.oracle">
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
  </driver>
</drivers>

Could that be an issue in Docker Compose where your standalone.xml is not overriding the default one in the image (at $JBOSS_HOME/standalone/configuration/standalone.xml)?

@jreed-cartago
Copy link

Pretty sure I'm overriding it. If I remove the volume mapping from my docker-compse and start it up again I don't see any mention of oracle.

However, when I used the cli I got the following error

 [standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=com.oracle)
{
    "outcome" => "failed",
    "failure-description" => "WFLYJCA0041: Failed to load module for driver [com.oracle]",
    "rolled-back" => true
}

So it could be something to do with how I'm injecting the module in via my dockerfile.

@jmesnil
Copy link
Author

jmesnil commented Mar 21, 2024

When you have built and run your image, could you run

docker exec -it 06c223e348db ls /opt/jboss/wildfly/modules/com/oracle/main

to make sure that module.xml &ojdbc11.jar are in that directory?

@jreed-cartago
Copy link

Yep they are there.

docker exec -it wildfly28_24.2.0 ls /opt/jboss/wildfly/modules/com/oracle/main
module.xml  ojdbc11.jar

@jmesnil
Copy link
Author

jmesnil commented Mar 21, 2024

I'm starting to run out of ideas...
Could the ojdbc11.jar have been corrupted when you download it. Does it jar tvf correctly?

I'm not familiar with docker compose but if you can drop its configuration I might see what could cause the issue

@jreed-cartago
Copy link

jreed-cartago commented Mar 21, 2024

It's possible there's something wrong with the jar file. I can download a fresh copy and see how that works.

Here is my docker-compose.yml file. It's pretty simple compared:

cartago@nunki:~/docker-files/wildfly28$ cat docker-compose.yml
services:
  wildfly28:
    user: "1000:1000"
    container_name: wildfly28_24.2.0
    image: wildfly28_dev:JDK17
    restart: unless-stopped
    ports:
      - "50080:8080"
    volumes:
      - /home/cartago/wildfly-home/wildfly28/24.2.0/deployments:/opt/jboss/wildfly/standalone/deployments
      - /home/cartago/wildfly-home/wildfly28/24.2.0/log:/opt/jboss/wildfly/standalone/log
      - /home/cartago/cartago-home:/opt/cartago-home

What I've omitted here was my mapping for the /opt/jboss/wildfly/standalone/configuration folder which would be mapped similar to the deployments and logs mapping. The cartago-home mapping is for our application once I get to the point where I can attempt to deploy it. This is simply a test environment for my team so I don't need to embedd it also in the image.

Update:
I downloaded a new copy of the ojdbc11.jar from Maven and it's still not working. Same error when I attempt to add the module via cli.

@jreed-cartago
Copy link

Once again I want to thank you for your assistance. Today it finally dawned on me what I did wrong. I made a typo in the module.xml which was so small it was easy to miss.

module xmlns="urn:joss:module:1.9" name="com.oracle"

Basically in the namespace I forgot the b in jboss. I can't believe that this was my problem. It works now and I'm getting the Success when I perform the manual adding of the oracle module.

@jmesnil
Copy link
Author

jmesnil commented Apr 2, 2024

@jreed-cartago Great that it works now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment