Prerequisite:
- Java version 1.6 +
- Eclipse latest J2EE version
- TomEE server latest version with full profile http://tomee.apache.org/downloads.html
- 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}
- Configure data source at EAR level
- First you have to identify which database to use. Then you have to download the specific version of JDBC driver
- Oracle jdbc driver http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
- MySQL Jdbc driver http://dev.mysql.com/downloads/connector/j/
- DB2 jdbc driver http://www-01.ibm.com/support/docview.wss?uid=swg21363866
- After downloading the driver copy the jar file to {TOMEE_HOME}/lib folder
- Create a J2EE Multi module Application project with following structure
- Open Application.xml file under EAR module at META-INF directory
- 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