Home Navigation

Thursday 6 October 2016

Setting up data source in TomEE at EAR level

Prerequisite:
  1. Configure TomEE to deploy EAR Application in Apps directory
    • Got to the directory {TOMEE_HOME}\conf\
    • Open the file tome.xml in a text editor
    • <Deployments dir="apps" /> add this tag to tome.xml
    • And Create a directory apps in {TOMEE_HOME}
  2. Configure data source at EAR level
      • Add the data-source information according to the database you have chosen. And make sure you add the schema as well. You can copy the below schema to your application.xml file

xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
version="6"

      • To get the database class name please follow the below link http://tomee.apache.org/common-datasource-configurations.html
      • Now open in a text editor web.xml file from WEB-INF directory of webmodule project and declare the resource reference you created in application.xml file in EAR module. Make sure the reference name is the same as data-source name in application.xml file.  
      • You can now call the datasource from your code. Below is an example of calling datasource from a jsp page.    
      • Build the application and copy the .ear file to {TOMEE_HOME}\apps directory.
      • Test the application web application from web browser.

No comments:

Post a Comment