4 Replies Latest reply on Sep 25, 2017 11:13 AM by davidi123

    Add driver in domain mode

    davidi123

      Hello everyone,

       

      I'm running my wildfly 10.0.0.Final in domain mode and want to add a datasource to a Mysql-Server.

       

      I tried to deploy the jdbc.jar to the server with this command:

      deploy <path-to-file>/mysql-connector-java-5.1.44-bin.jar --all-server-groups
      

       

      Then I tried to run this script to add the datasource:

      /profile=ha/subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-class-name="${db.driver}")
      /profile=ha/subsystem=datasources/data-source=mysqlDS:add(jndi-name="${db.jndi_name}",  driver-name=mysql,  connection-url="${db.url}", user-name="${db.user}", password="${db.password}", enabled=true, use-java-context=true )
      

       

      This is my properties file:

      db.driver=com.mysql.jdbc.Driver
      db.jndi_name=java:/Sample_MySQL
      db.url=jdbc:mysql://192.168.56.1:3306/employees
      db.user=admin
      db.password=admin
      

       

      The result is the following error:

      Failed to load module for driver [com.mysql]

       

      What do I have to do to use the driver?

      Kinde regards,

      David

        • 1. Re: Add driver in domain mode
          jewellgm

          Rather than deploying your jar, you need to create a Wildfly module and put your jar into it.  Look into the %WILDFLY_HOME%\modules directory, where all of the modules reside.  You'll find many examples of how to create a module.  You'll need to create a directory structure, which in your example, would be "com/mysql/main".  Drop your jar into there, and create a module.xml file in the same location.  You can use the existing com.h2database.h2 module as a template.

          • 2. Re: Add driver in domain mode
            davidi123

            I placed the module.xml and the driver.jar into the folder "<wildfly>/modules/system/layers/base/com/mysql/main" now.

            When I run the script again, I get the same error, but this time for the slave only. It seems, that it doesn't deploy the two files to the slave.

            When I shut down the slave and only run the master, it is working.

            Do I have to do it manually at all the slaves or is there a possibility to deploy it automatically?

            • 3. Re: Add driver in domain mode
              jewellgm

              There's no automatic deployment of modules to slaves that I'm aware of.  You can either install the module on each slave manually, or utilize a patching mechanism to push patches from the master down to slaves.  I found two links, but one of them is being blocked by the firewall.

               

              Layered Distributions and Module Path Organization

               

              http://aparnachaudhary.github.io/blog/2014/11/wildfly-patch-custom-module.html  (<- Blocked by firewall)

              1 of 1 people found this helpful
              • 4. Re: Add driver in domain mode
                davidi123

                Ok, I applied a patch to my master host as described here: http://aparnachaudhary.github.io/blog/2014/11/wildfly-patch-custom-module.html and restarted the server.

                I think it worked because the script ran without error and I can see the datasource.

                I also see the patch at <wildfly>/.installation/patches/ and the jar + module.xml in <wildfly>/modules/com/mysql/main.

                 

                But what confuses me is that the patch doesn't appear in the wildfly console.

                Patches.PNG

                Using the jboss-cli.sh and the command: "patch --host=master history" I get this result

                {
                    "outcome" : "success",
                    "result" : [],
                    "server-groups" : null
                }
                

                 

                And when I try to rollback with "patch rollback --host=master --reset-configuration=true", I get this error:

                {"master" => "java.lang.IllegalArgumentException: WFLYPAT0020: Cannot rollback. No patches applied."}}