3 Replies Latest reply on Oct 30, 2017 8:51 AM by Paramvir Jindal

    Execute CLI command using patch file

    Milan Pleša Newbie



      i have created custom patch file for postgresql driver(among other things too). The problem is that i have to registed driver for my profile(domain mode).

      Is it possible to execute CLI domands like this one ./subsystem=datasources/jdbc-driver=postgresql:add( driver-module-name=org.postgresql.jdbc,  driver-name=postgresql) when uploading patch?


      Is there some other way that a jdbc driver can work without using CLI command to register jdbc driver?


      Thank you in advance.

        • 1. Re: Execute CLI command using patch file
          Paramvir Jindal Newbie

          You can create/upload module for JDBC driver using a CLI(disconnected mode don't provide "-c" or "--connect" while connecting to CLI) command like below :


          [pjindal@pjindal bin]$ ./jboss-cli.sh

          [disconnected /] module add --name=com.postgres.jdbc --resources=<path-to-your-driver>/postgresql-9.0-802.jdbc4.jar --dependencies=javax.api,javax.transaction.api


          This will add a new module in the Wildfly's default module directory with  the structure /modules/com/postgres/jdbc/main along with the required module.xml with the following content :



          <?xml version="1.0" ?>


          <module xmlns="urn:jboss:module:1.1" name="com.postgres.jdbc">



                  <resource-root path="postgresql-9.0-802.jdbc4.jar"/>




                  <module name="javax.api"/>

                  <module name="javax.transaction.api"/>





          And later you can configure the driver using this created module using below command (This time in connected mode of JBoss CLI) :


          [domain@localhost:9990 /] /profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-module-name=com.postgres.jdbc,driver-name=postgres)

          • 2. Re: Execute CLI command using patch file
            Milan Pleša Newbie

            thank you very much for the answer but that whole part has been done. I'm trying to do this part /profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-module-name=com.postgres.jdbc,driver-name=postgres) without connecting to the jboss console.


            The patch has the driver module already in it and after patching it is placed in the modules directory. When i register driver with the CLI command above everything works fine.

            The thing that I'm trying to accomplish is to avoid CLI command also as going to the GUI admin console to add jdbc-driver to the datasources. I'm just wondering if something like that is even possible

            • 3. Re: Execute CLI command using patch file
              Paramvir Jindal Newbie

              If you don't want to configure the jdbc-driver at all (neither using CLI nor using admin console) and still want to use a driver in your datasource configuration then you have an option to directly deploy the jdbc driver's jar file (let's say on main-server-group) just like any other deployment using CLI or admin console and then just specify the complete jar name in your datasource configuration like below :


              <datasource jndi-name="java:jboss/PostgresDS" pool-name="PostgresDS">








                    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker>

                    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"></exception-sorter>




              And it will work. This way to don't have to configure the driver at all. Just deploy it (assign it to any group and enable it) and specify the full name of driver jar under datasource configuration like above.