9 Replies Latest reply on May 31, 2016 5:31 PM by Eudris Cabrera Rodriguez

    wildfly maven plugin fail to deploy mysql datasource

    Henk van den Toorn Newbie

      Dear all,

       

      I'm trying to set up an EAR project from Netbeans, using the wildfly-maven-plugin (1.0.2-Final) in a maven project.

      I'm able to upload the mysql connector as a jdbc driver, and I can create a datasource manually based on it. Unfortunately, when I try to deploy a datasource, it does not work failing with a message about the driver not found.

       

      My configuration looks like this:

                <plugin>

                      <groupId>org.wildfly.plugins</groupId>

                      <artifactId>wildfly-maven-plugin</artifactId>

                      <version>1.0.2.Final</version>

                      <configuration>

                          <jboss-home>${wildfly-home}</jboss-home>

                      </configuration>

                     

                      <executions>

                          <execution>

                              <id>deploy_jdbc_driver</id>

                              <phase>package</phase>

                              <goals>

                                  <goal>deploy-artifact</goal>

                              </goals>

                              <configuration>

                                  <groupId>${mysql.driver.groupId}</groupId>

                                  <artifactId>${mysql.driver.artifactId}</artifactId>

                                  <version>${mysql.driver.version}</version>

                                  <name>${mysql.driver.name}</name>

                                  <driver-name>${mysql.driver.name}</driver-name>

                              </configuration>

                          </execution>

                          <execution>

                              <id>add_datasource</id>

                              <phase>package</phase>

                              <goals>

                                  <goal>add-resource</goal>

                              </goals>

                              <configuration>

                                  <address>subsystem=datasources,data-source=java:jboss/datasources/qcdb</address>

                                  <resources>

                                      <resource>

                                          <properties>

                                              <jndi-name>java:jboss/datasources/qcdb</jndi-name>

                                              <connection-url>${db.jdbc.url}</connection-url>

                                              <driver-class>com.mysql.jdbc.Driver</driver-class>

                                              <driver-name>${mysql.driver.name}</driver-name>

                                              <enabled>true</enabled>

                                              <database-name>${mysql.db.schema}</database-name>

                                              <security.user-name>${mysql.db.user}</security.user-name>

                                              <security.password>${mysql.db.password}</security.password>

                                              <pool-name>qcdb_pool</pool-name>

                                          </properties>

                                      </resource>

                                  </resources>

                              </configuration>

                          </execution>

                      </executions>

                  </plugin>

       

      With the relevant properties above:

       

      <properties>

          <mysql.server>localhost</mysql.server>

          <mysql.port>3306</mysql.port>

          <mysql.driver.groupId>mysql</mysql.driver.groupId>

          <mysql.driver.artifactId>mysql-connector-java</mysql.driver.artifactId>

          <mysql.driver.version>5.1.34</mysql.driver.version>

          <mysql.db.schema>qcdb</mysql.db.schema>

          <mysql.db.user>qcdb</mysql.db.user>

          <mysql.db.password>qcdb</mysql.db.password>

          <db.jdbc.url>jdbc:mysql://${mysql.server}:${mysql.port}/qcdb</db.jdbc.url>

          <mysql.driver.name>${mysql.driver.artifactId}-${mysql.driver.version}</mysql.driver.name>

          <wildfly-home>c:/wildfly-8.2.0.Final/</wildfly-home>

          <wildfly.hibernate.datasource.name>java:/jboss/datasources/qcdb</wildfly.hibernate.datasource.name>

      </properties>

       

      Moreover I have a dependency on the mysql connector like so:

       

             <dependency>

                  <groupId>${mysql.driver.groupId}</groupId>

                  <artifactId>${mysql.driver.artifactId}</artifactId>

                  <version>${mysql.driver.version}</version>

                  <scope>provided</scope>

             </dependency>

       

      Unfortunately, the error I get is this:

       

      Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.0.2.Final:add-resource (add_datasource) on project qcCollector: Could not execute goal add-resource. Reason: Operation failed: {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => {"JBAS014771: Services with missing/unavailable dependencies" => [

      "jboss.data-source.java:jboss/datasources/qcdb is missing [jboss.jdbc-driver.mysql-connector-java-5_1_34]",

      "jboss.driver-demander.java:jboss/datasources/qcdb is missing [jboss.jdbc-driver.mysql-connector-java-5_1_34]"

      ]}}}

       

      Can anybody please help me to get this resolved? It's driving me nuts, especially because I think it worked once..

       

      Regards, Henk

        • 1. Re: wildfly maven plugin fail to deploy mysql datasource
          James Perkins Master

          Have you tried changing the deploy-artifact goal to bind to an earlier lifecycle phase?

           

          --

          James R. Perkins

          • 2. Re: wildfly maven plugin fail to deploy mysql datasource
            Henk van den Toorn Newbie

            Hi, thank you for answering. I have tried, but to no avail. I even moved the add_datasource to a different project in my maven reactor build..

            Possibly I'm using the wrong properties?

             

            I'm now starting to doubt if the driver is deployed in the correct way, as it shows up in the "applications" deployments. Is that what is supposed to happen, or is it wrong?

            • 3. Re: wildfly maven plugin fail to deploy mysql datasource
              James Perkins Master

              What version of WildFly are you using?

               

              Are you seeing any messages about the driver being deployed?

               

              --

              James R. Perkins

              • 4. Re: wildfly maven plugin fail to deploy mysql datasource
                Henk van den Toorn Newbie

                I'm using version 8.2. [EDIT] I see the deployment in the server logs:

                 

                08:58:29,084 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-13) JBAS015876: Starting deployment of "mysql-connector-java-5.1.35" (runtime-name: "mysql-connector-java-5.1.35")

                08:58:29,124 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-10) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)

                08:58:29,125 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-10) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)

                08:58:29,125 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010417: Started Driver service with driver-name = mysql-connector-java-5.1.35_com.mysql.jdbc.Driver_5_1

                08:58:29,125 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-9) JBAS010417: Started Driver service with driver-name = mysql-connector-java-5.1.35_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1

                08:58:29,136 INFO  [org.jboss.as.server] (management-handler-thread - 1) JBAS018559: Deployed "mysql-connector-java-5.1.35" (runtime-name : "mysql-connector-java-5.1.35")

                08:58:29,552 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 4) JBAS014613: Operation ("add") failed - address: ([

                    ("subsystem" => "datasources"),

                    ("data-source" => "java:jboss/datasources/qcdb")

                ]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => [

                    "jboss.driver-demander.java:jboss/datasources/qcdb is missing [jboss.jdbc-driver.mysql-connector-java-5_1_35]",

                    "jboss.data-source.java:jboss/datasources/qcdb is missing [jboss.jdbc-driver.mysql-connector-java-5_1_35]"

                ]}

                08:58:29,553 INFO  [org.jboss.as.controller] (management-handler-thread - 4) JBAS014774: Service status report

                JBAS014775:    New missing/unsatisfied dependencies:

                      service jboss.data-source.reference-factory.java:jboss/datasources/qcdb (missing) dependents: [service jboss.naming.context.java.jboss.datasources.qcdb]

                      service jboss.data-source-config.java:jboss/datasources/qcdb (missing) dependents: [service jboss.data-source.java:jboss/datasources/qcdb]

                      service jboss.jdbc-driver.mysql-connector-java-5_1_35 (missing) dependents: [service jboss.driver-demander.java:jboss/datasources/qcdb, service jboss.data-source.java:jboss/datasources/qcdb]

                • 5. Re: wildfly maven plugin fail to deploy mysql datasource
                  James Perkins Master

                  It looks like MySQL has two different drivers; com.mysql.jdbc.Driver and com.mysql.fabric.jdbc.FabricMySQLDriver. You'll see in the following CLI command you'll see the installed driver name doesn't match.

                  [standalone@localhost:9990 /] /subsystem=datasources:installed-drivers-list
                  {
                      "outcome" => "success",
                      "result" => [
                          {
                              "driver-name" => "mysql-connector-java-5.1.34.jar_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1",
                              "deployment-name" => "mysql-connector-java-5.1.34.jar_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1",
                              "driver-module-name" => undefined,
                              "module-slot" => undefined,
                              "driver-datasource-class-name" => undefined,
                              "driver-xa-datasource-class-name" => undefined,
                              "driver-class-name" => "com.mysql.fabric.jdbc.FabricMySQLDriver",
                              "driver-major-version" => 5,
                              "driver-minor-version" => 1,
                              "jdbc-compliant" => false
                          },
                          {
                              "driver-name" => "mysql-connector-java-5.1.34.jar_com.mysql.jdbc.Driver_5_1",
                              "deployment-name" => "mysql-connector-java-5.1.34.jar_com.mysql.jdbc.Driver_5_1",
                              "driver-module-name" => undefined,
                              "module-slot" => undefined,
                              "driver-datasource-class-name" => undefined,
                              "driver-xa-datasource-class-name" => undefined,
                              "driver-class-name" => "com.mysql.jdbc.Driver",
                              "driver-major-version" => 5,
                              "driver-minor-version" => 1,
                              "jdbc-compliant" => false
                          },
                          {
                              "driver-name" => "postgresql.jar",
                              "deployment-name" => "postgresql.jar",
                              "driver-module-name" => undefined,
                              "module-slot" => undefined,
                              "driver-datasource-class-name" => undefined,
                              "driver-xa-datasource-class-name" => undefined,
                              "driver-class-name" => "org.postgresql.Driver",
                              "driver-major-version" => 9,
                              "driver-minor-version" => 3,
                              "jdbc-compliant" => false
                          },
                          {
                              "driver-name" => "h2",
                              "deployment-name" => undefined,
                              "driver-module-name" => "com.h2database.h2",
                              "module-slot" => "main",
                              "driver-datasource-class-name" => "",
                              "driver-xa-datasource-class-name" => "org.h2.jdbcx.JdbcDataSource",
                              "driver-class-name" => "org.h2.Driver",
                              "driver-major-version" => 1,
                              "driver-minor-version" => 3,
                              "jdbc-compliant" => true
                          }
                      ]
                  }
                  

                   

                  So if you change your driver-name from mysql-connector-java-5.1.34 to mysql-connector-java-5.1.34_com.mysql.jdbc.Driver_5_1 it should work.

                   

                  --

                  James R. Perkins

                  • 6. Re: wildfly maven plugin fail to deploy mysql datasource
                    Henk van den Toorn Newbie

                    You are absolutely right, that's the problem and your solution is what made it work! Thanks a lot for your effort.

                    Would there be a way to get this to work based on the driver-class-name? It's unfortunate that Oracle's own open-source database does not seem to comply with the jdbc standards..

                    • 7. Re: wildfly maven plugin fail to deploy mysql datasource
                      Jesper Pedersen Master

                      Deploy your JDBC driver as a module, and select the driver class to use by specifying <driver-class> in the <driver> definition.  Or use James' approach.

                       

                      You can have as many java.sql.Driver implementations inside a JDBC driver as you want.

                      • 8. Re: wildfly maven plugin fail to deploy mysql datasource
                        Henk van den Toorn Newbie

                        Hi Jesper,

                         

                        Thanks for entering the discussion. I've read before that you should deploy mysql as a module, but I couldn't find out how to do that from maven. There was a discussion on stackoverflow more than a year ago now (How to deploy mysql datasource using jboss-as-maven-plugin - Stack Overflow), of someone saying they wrote their own plugin to do that, but I couldn't find what the name of this plugin is and if it's available.

                        The approach of James does work (therefore I selected it as the answer) but it's not ideal, i.e. you'd have to find out the correct name of the driver from inside the artifact, maybe the naming convention will change in the future again. Therefore I'd prefer the module way...

                         

                        I'm sort of surprised there is no easy to find answer for this, am I the only one using mysql/jboss/maven??

                        • 9. Re: wildfly maven plugin fail to deploy mysql datasource
                          Eudris Cabrera Rodriguez Newbie

                          Hi,

                           

                          Wildfly maven plugin fail to deploy mysql datasource.

                          Starting from mysql connector 5.1.30, adding datasource mysql is not working.

                          Does anybody know if this issue has been resolved ?.

                          Thanks in advance !!.