This article is written to show how to add datasource in Wildfly Java Application Server. As far as it is, there are two ways which can be used in order to add datasource in Wildfly Java Application Server. The first one is using the web interface provided after the service of Wildfly Management Console is activated and the second one is by using the command executed via command line of the Wildfly Management Console Command Prompt line. In this article, the main focus is about how to add datasource in Wildfly Java Application Server by using a certain command pattern via command line. Precisely, the command line is in the Wildfly Management Console Command Prompt line where in that command prompt line, only the specific command related to manage Wildfly Java Application Server can be executed.
In this context, the command specified is indeed on how to add datasource in Wildfly Java Application Server. The datasource which is going to be added is a datasource for application deployed in Wildfly Java Application Server. It is a datasource where the application can connect to MySQL Database Server using the specified datasource configuration. Below is the command pattern for adding datasource which is a configurationi connection to MySQL Database Server from the application deployed :
data-source add --name=datasource_name --jndi-name=java:/jdbc/jndi_jdbc_name --driver-name=mysql-connector-java-jar-file-name.jar --connection-url=jdbc:mysql://localhost:3306/db_name --user-name=db_user --password=db_password
The actual execution command is shown as follows :
[standalone@localhost:9990 /] data-source add --name=my-datasource --jndi-name=java:/jdbc/my-jndi-datasource --driver-name=mysql-connector-java-8.0.11.jar --connection-url=jdbc:mysql://localhost:3306/testing --user-name=root --password=password operation-requires-reload: true process-state: reload-required [standalone@localhost:9990 /]
The above command execution in the Wildfly Management Console is an actual process for adding datasource. But in order to use the datasource in an actual application deployment, the Wildfly Java Application Server first need to be reloaded. The following is the actual process for reloading the Wildlfy Java Application Server :
[standalone@localhost:9990 /] :reload { "outcome" => "success", "result" => undefined } [standalone@localhost:9990 /]
Since based on the output generated from the above ‘:reload’ command executed in the Wildfly Management Console has the outcome of “success”, the process of adding the datasource has already successfully carried out.
2 thoughts on “How to Add Datasource in Wildfly Java Application Server via Command Line”