pondělí 28. ledna 2013

JBoss AS 7.1 with Mysql Server step-by-step

Today we've struggled for more then three hours figuring out how to use Mysql on our JBoss server. I am going to describe steps by step because I found this very confusing.

Lets get started. I assume you have downloaded and extracted JBoss 7.1 AS

There are two ways how you can use Mysql in JBoss. We are going the easier one because in the second one you have to edit 1400lines long XML (the bloody hell!!).

  1. download Mysql Java Connector
  2. extract .jar to separete folder (for example mysql-connector-java-5.1.22-bin.jar)
  3. in that folder create directory META-INF and inside that one create services and there create file called java.sql.Driver (so it will look META-INF/services/java.sql.Driver)
  4. into that driver write only this line:
  5. go back to the folder with .jar and run this command (replace name of your /jar accordingly):
    jar -uf mysql-connector-java-5.1.22-bin.jar  META-INF/services/java.sql.Driver
  6. go to your JBoss bin folder and run script add-user.bat (add-user-sh on unix)
  7. choose a) Management User (mgmt-users.properties) -> ENTER -> fill username -> fill password -> repeat password
  8. in your browser open http://localhost:9990/console/ and login using that username/password
  9. in administration console switch to Runtime (upper right corner) and then choose Manage Deployments. There click on the Add Content button and choose path the .jar extracted above. At last click on the enable button. Finally it should look like this:
  10. switch to Profile (upper right corner http://localhost:9990/console/App.html#datasources) and open Connector / Datasources and click on the Add button
  11. specify name and JNDI name - you will fill this up in your persistent.xml. Remember that JNDI name must begin with java:/ ... so for example java:/testDS
  12. in second step choose mysql-connector-java-5.1.22-bin.jar connector.
  13. connection URL will look like: jdbc:mysql://localhost/database_name
  14. fill also your mysql username and mysql password and click on Done (leave security domain blank).
  15. now click on the Enable button to enable datasource
  16. 2
    in your persistent.xml you can use created datasource like this:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
   xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   <persistence-unit name="primary">
         <property name="hibernate.hbm2ddl.auto" value="create-drop" />
         <property name="hibernate.archive.autodetection" value="class" />

Source: https://community.jboss.org/wiki/DataSourceConfigurationInAS7

Žádné komentáře: