title: How to deploy mysql datasource using jboss-as-maven-plugin
body: <p>This question is here to give an answer to once i find a solution, I have found documentation on Postgresql and H2 databases from the jboss <a href="http://docs.jboss.org/jbossas/7/plugins/maven/latest/examples/add-resource-example.html" rel="nofollow">website</a> and have seen how it is done manually through this <a href="https://community.jboss.org/wiki/DataSourceConfigurationInAS7" rel="nofollow">website</a>, however I cannot seem to find much information on how to deploy a mysql datasource using the jboss-as-maven-plugin.</p>
  
  <p>What is the minimum configuration properties required to properly register a mysql datasource with jboss-as 7 server through their maven plugin?</p>
  
  <p>I have this dependency:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>And this configuration for the maven plugin</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;build&gt;
      &lt;plugins&gt;
          ...
          &lt;plugin&gt;
              &lt;groupId&gt;org.jboss.as.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;jboss-as-maven-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;execute-commands/&gt;
                  &lt;executeCommands/&gt;
                  &lt;properties&gt;
                      &lt;enable-welcome-root&gt;false&lt;/enable-welcome-root&gt;
                  &lt;/properties&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  ...
                  &lt;!-- deploy the mysql connectorj --&gt;
                  &lt;execution&gt;
                      &lt;id&gt;deploy-mysql-driver&lt;/id&gt;
                      &lt;phase&gt;install&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;deploy-artifact&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;groupId&gt;mysql&lt;/groupId&gt;
                          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
                          &lt;name&gt;mysql.jar&lt;/name&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;deploy&lt;/id&gt;
                      &lt;phase&gt;install&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;deploy&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;add-datasource&lt;/id&gt;
                      &lt;phase&gt;deploy&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;add-resource&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;address&gt;subsystem=datasources&lt;/address&gt;
                          &lt;resources&gt;
                              &lt;resource&gt;
                                  &lt;address&gt;xa-data-source=java:global/datasources/tncDS&lt;/address&gt;
                                  &lt;enable-resource&gt;true&lt;/enable-resource&gt;
                                  &lt;properties&gt;
                                      &lt;jndi-name&gt;java:jboss/datasources/tncDS&lt;/jndi-name&gt;
                                      &lt;enabled&gt;true&lt;/enabled&gt;
                                      &lt;connection-url&gt;jdbc:mysql://localhost:3306/tnc&lt;/connection-url&gt;
                                      &lt;driver-class&gt;com.mysql.jdbc.Driver&lt;/driver-class&gt;
                                      &lt;driver-name&gt;mysql.jar&lt;/driver-name&gt;
                                  &lt;/properties&gt;
                              &lt;/resource&gt;
                          &lt;/resources&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              ...
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>running the command <code>mvn jboss-as:run</code> causes this error:</p>
  
  <pre class="lang-xml prettyprint-override"><code>[INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 7.241s
  [INFO] Finished at: Tue Sep 24 21:37:28 EST 2013
  [INFO] Final Memory: 16M/308M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:deploy-artifact (deploy-mysql-driver) on project ear: Could not execute goal deploy-artifact on null. Reason: I/O Error could not execute operation '{
  [ERROR] "address" =&gt; [],
  [ERROR] "operation" =&gt; "read-attribute",
  [ERROR] "name" =&gt; "launch-type"
  [ERROR] }': java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9999. The connection timed out
  [ERROR] -&gt; [Help 1]
  [ERROR] 
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR] 
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  </code></pre>
  
  <p><b>UPDATE:</b></p>
  
  <p>I have developed a plugin that injects the required file (<code>META-INF/services/java.sql.Driver</code>) into the jar before deployment:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;plugin&gt;
      &lt;groupId&gt;com.thenaglecode&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-jdbc-compliance-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;configuration&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.26&lt;/version&gt;
      &lt;/configuration&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;goals&gt;
                  &lt;goal&gt;modify-connector&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;phase&gt;package&lt;/phase&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>However i'm still getting <code>could not connect to remote</code> message. Is there a step that i'm missing or doing in the wrong sequence as i understand that the run command should start up the server.</p>
  
  <p><b>UPDATE 2:</b><br/>
  After some fiddling and reading of the jboss-as plugin <a href="http://docs.jboss.org/jbossas/7/plugins/maven/latest/examples/complex-example.html" rel="nofollow">website</a>, I realized that the <code>jboss-as:run</code> goal also invokes the <code>package</code> phase. I was mostly receiving this error when I tried to run any of the deploying goals bound to the <code>package</code> phase.</p>
  
  <p><b>Anything that needs to be deployed should be bound to the <code>install</code> phase.</b></p>
  
  <p>I am now getting a seperate error regarding my persistence unit not existing</p>