#### Integrating by building a user EAR and embedding a self-contained JReport Server

You can embed a self-contained JReport Server into your EAR in order to use JReport Server from EJB.

##### Structure of the user EAR

For example, here you can create an EAR named MyApp.ear and then embed a self-contained JReport Server inside it. In the EAR, there is an EJB module used for initializing JReport Server. The structure of your EAR may be as follows:

MyEAR.ear

META-INF/application.xml

jreport-lib/ -- This folder contains all resources in the JReport Server library

MyEjb.jar

META-INF/

MANIFEST.MF

ejb-jar.xml

com/

##### META-INF/application.xml

Following the Java EE standard, you should configure the META-INF/application.xml file before deploying your EAR:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
    "http://java.sun.com/dtd/application_1_3.dtd">

    <application>
        <display-name>EJB with Embedded JReport Server</display-name>
        <module id="MyEJBModule">
            <ejb>MyEjb.jar</ejb>
        </module>
    </application>

##### META-INF/MANIFEST.MF of EJB module

Since the JReport Server library is included in the jreport-lib folder of the EAR layer, you must specify Class-Path in the META-INF/MANIFEST.MF file. The contents below should be included in the MANIFEST.MF file:

`Class-Path: jreport-lib/jrenv.jar jreport-lib/JRESServlets.jar jreport-lib/JREngine.jar ...`

Class-Path is a list of all packages in the JReport Server library. Each package name should start with the prefix jreport-lib/, and you should use a blank space to separate package names.

##### META-INF/ejb-jar.xml

If you do not want to set the reporthome for the embedded self-contained JReport Server, but instead want to use JReport's default settings, there is no requirement for configuring the ejb-jar.xml. However, if you want to control the reporthome of the JReport Server, or specify a JNDI data source for JReport Server to use, you should first configure the ejb-jar.xml file using the `<env-entry></env-entry>` tags.

Here is an example:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
    "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

    <ejb-jar id="ejb-jar_ID">
        <display-name>MyEJB</display-name>
        <enterprise-beans>
            <session id="JReportEJB">
                <ejb-name>JRptServer</ejb-name>
                <home>demo.JRptServerHome</home>
                <remote>demo.JRptServer</remote>
                <ejb-class>demo.JRptServerBean</ejb-class>
                <session-type>Stateless</session-type>

                <!-- Specify JReport reporthome directly
                    <env-entry>
                    <env-entry-name>jreport.rpthome</env-entry-name>
                    <env-entry-value>/home/jreport</env-entry-value>
                    <env-entry-type>java.lang.String</env-entry-type>
                    </env-entry>
                -->

                <!-- JReport callback my CustomizedServerEnv -->
                <env-entry>
                    <env-entry-name>jreport.servenv</env-entry-name>
                    <env-entry-value>demo.JReportServerEnv</env-entry-value>
                    <env-entry-type>java.lang.String</env-entry-type>
                </env-entry>

                <transaction-type>Bean</transaction-type>
            </session>
        </enterprise-beans>
    </ejb-jar>