Thursday, March 22, 2007

deploy a J2EE Web application to the OC4J Web server


Introduction





You can deploy a J2EE Web application to the OC4J Web server using either the
-deploy
option with the admin.jar command line tool or by
manually adding the appropriate elements to the OC4J XML configuration files. The
following document explains how to deploy an application to the OC4J server using
both methods.


For the purpose of this document, I will provide all examples using a fictitious
application called my_app.



Before performing the actual "deployment" steps to OC4J, you will need to perform
the following actions:





  • DataSource - (optional) If your application will be require access to an
    external data source (i.e. a relational database) you will need to configure the
    data-sources.xml file by adding the appropriate <data-source ...
    />
    element. For example:

    <data-source
    class="com.evermind.sql.DriverManagerDataSource"
    name="OracleDS"
    location="jdbc/OracleCoreDS"
    xa-location="jdbc/xa/OracleXADS"
    ejb-location="jdbc/OracleDS"
    connection-driver="oracle.jdbc.driver.OracleDriver"
    username="scott"
    password="tiger"
    url="jdbc:oracle:thin:@<database_server>:<database_port>:<oracle_sid>"
    inactivity-timeout="30"
    />




  • Next, copy the Enterprise Application Archive file (*.ear file) to the $OC4J_HOME/j2ee/home/applications
    directory.

    % cp my_app.ear $OC4J_HOME/j2ee/home/applications






Deploying Application Using admin.jar -deploy





You can make use of the admin.jar command-line utility to deploy the
my_app application. The following two commands can be used to deploy the
J2EE application as well as the Web application. Using this method allows for remote
deployment.




  • Register the J2EE application (generally the EJBs / business logic):

    % java -jar admin.jar ormi://<oc4j_host>:<oc4j_ormi_port> admin manager
    -deploy -file $OC4J_HOME/j2ee/home/applications/my_app.ear -deploymentName my_app
    -targetPath applications/


    This step creates the entry in the server.xml file for the my_app
    application.





  • To bind the Web application through the admin.jar tool, use the following:

    % java -jar admin.jar ormi://<oc4j_host>:<oc4j_ormi_port> admin manager
    -bindWebApp my_app my_app-web http-web-site /my_app


    This creates the <web-app> entry element in the http-web-site.xml
    configuration file.





  • If the OC4J server is not running, use the following to start the OC4J instance:

    % cd $OC4J_HOME/j2ee/home
    % java -jar oc4j.jar -verbosity 10




  • The application should now be accessible from the following URL:

    http://<oc4j_host>:8888/my_app






Deploying Application by Manually Adding XML Elements





In order to register the my_app applciation, you will need to add the J2EE
application in the server.xml file and its Web application in the
http-web-site.xml
file.




  • In the $OC4J_HOME/j2ee/home/config/server.xml file, add the my_app
    entry, as follows:

    <application name="my_app"
    path="../applications/my_app.ear"
    auto-start="true" />




  • In the $OC4J_HOME/j2ee/home/config/http-web-site.xml file, bind the
    my_app application by adding the web-app entry, as follows:

    <web-app application="my_app"
    name="my_app-web"
    root="/my_app"
    load-on-startup="true" />


    This step will make the application accessible from the OC4J server.





  • If the OC4J server is not running, use the following to start the OC4J instance:

    % cd $OC4J_HOME/j2ee/home
    % java -jar oc4j.jar -verbosity 10




  • The application should now be accessible from the following URL:

    http://<oc4j_host>:8888/my_app



No comments: