4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WildFlyでMySQL datarouceの作成

Last updated at Posted at 2014-04-08

概要

WildFlyにJDBCドライバを設定し、datasourceを作成する。
modulesディレクトリにjarを配置してxmlを編集する方法もあるが、WildFlyの推奨にしたがって、jarをデプロイする方法でやってみる。こうすることでdomainモードでも個々のサーバに設定する必要がなくなる。

環境

  • Linux Mint 16 Petra
  • WildFly 8.0.0.Final
  • MySQL Connector/J 5.1.30

事前準備

MySql にexampleデータベースを作成しておく。

内容

  • MySQLのJDBCドライバをダウンロードして解凍。
$ wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.30.zip
$ unzip mysql-connector-java-5.1.30.zip
  • デプロイするためのファイルを作成。

 (2014/4/17 追記 mysqlのjarにはすでにMETA-INF以下があるため、この作業とjarの更新は必要ないようです。jarをそのままデプロイするだけでよいです。)

$ cd mysql-connector-java-5.1.30
$ mkdir -p META-INF/services
$ vi META-INF/services/java.sql.Driver
META-INF/services/java.sql.Driver
com.mysql.jdbc.Driver
  • jarを更新
$ jar \-uf mysql-connector-java-5.1.30-bin.jar META-INF/services/java.sql.Driver
  • 管理コンソールのRuntime -> Manage Deployments から先程更新したjarをデプロイする。デプロイ後にEn/Disableボタンを押して有効化しておく。

jdbc_deployment.png

  • 管理コンソールのProfile -> Datasrouces -> JDBC Datasources からdatasourceを追加する。
Step 1/3: Datasource Attributes

Name: mysqlexampleDS
JNDI Name: java:/mysqlexampleDS
Step 2/3: JDBC Driver

先程デプロイしたmysql-connector-java-5.1.30-bin.jarを選択する。
Step 3/3: Connection Settings

Connection URL: jdbc:mysql://localhost:3306/example
Username: example
Password: example
  • 最後にEnableボタンを押して有効化する。

datasource.png

  • 下の方にあるConnectionからTest Connectionを押して疎通することを確認する。

testconnection.png

参考

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?