If you want Magnolia to use an external database, such as, Oracle, MySQL, Postgres, etc. with a JNDI datasource then you are going to want to create a (JBoss) module for your JBDC driver. I suggest doing this prior to Magnolia installation if possible, otherwise I would just move the webapp out of the deployment directory while setting this up. This way you can start and stop the server without having to wait for Magnolia.
Table of Contents |
---|
Create a Driver Module
- Create a file path structure under the
JBOSS_HOME/modules/
directory. For example, for an Oracle JDBC driver, create a directory structure as follows:JBOSS_HOME
/modules/oracle/jdbc/main/ - Copy the JDBC driver JAR into the
main/
subdirectory. In the
main/
subdirectory, create amodule.
xml
file:Code Block language xml <module xmlns="urn:jboss:module:1.1" name="com.oracle"> <resources> <resource-root path="ojdbc7.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>
The directory should look like this:
- Start the Server:
JBOSS_HOME
/bin/standalone.sh - Start the Management CLI in another command window:
JBOSS_HOME/bin/jboss-cli.sh --connect controller=localhost:9999
Run the following CLI command to add the JDBC driver module as a driver:
Code Block language bash /subsystem=datasources/jdbc-driver=DRIVER_NAME:add(driver-name=DRIVER_NAME,driver-module-name=MODULE_NAME,driver-xa-datasource-class-name=XA_DATASOURCE_CLASS_NAME)
An example for this scenario would be:
Code Block language bash /subsystem=datasources/jdbc-driver=oracle:add(driver-name=oracle,driver-module-name=com.oracle,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource)
Note: After running this command you should see something similar to the following in the server log:
INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 12.1)
- Shut down the Management CLI and shut down the server.
Verify the Driver Installation
Check you standalone.xml file. You should now see something like this:
Code Block language xml <subsystem xmlns="urn:jboss:domain:datasources:1.2"> <datasources> <drivers> <driver name="oracle" module="com.oracle"> <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class> </driver> </drivers> </datasources> </subsystem>
Configure the JNDI Datasource
Within the same subsystem your driver is configured, you can now declare the JNDI datasource.
Code Block | ||
---|---|---|
| ||
<subsystem xmlns="urn:jboss:domain:datasources:1.2"> <datasources> <datasource jndi-name="java:jboss/datasources/jackrabbit" pool-name="jackrabbit" enabled="true"> <connection-url>jdbc:oracle:thin:@127.0.0.1:xe</connection-url> <driver-class>oracle.jdbc.OracleDriver</driver-class> <driver>oracle</driver> <security> <user-name>schema</user-name> <password>password</password> </security> </datasource> <drivers> <driver name="oracle" module="com.oracle"> <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class> </driver> </drivers> </datasources> </subsystem> |
Verify the JNDI Datasource
Once you have added the JNDI datasource declaration into your standalone.xml you should now be ready to use it. To verify that start the server back up and look for the following in the log:
INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-15) JBAS010400: Bound data source [java:jboss/datasources/jackrabbit]
Now you're ready to deploy Magnolia. You can refer to your JNDI datasource in your JR repo config file.