Justin.Lu----Position

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  4 随笔 :: 6 文章 :: 3 评论 :: 0 Trackbacks

How To Use Eclipse with Oracle Containers for J2EE (OC4J)

Author: Tugdual Grall
Date: 12/05/04

Introduction

One of the benefits of the J2EE platform is that all the different artifacts are well defined, thereby allowing you to choose any development tools or containers you wish. The Lomboz plug-in for Eclipse comprises a wizard and a set of tools that enable J2EE to develop Servlets, JSPs, and EJBs and to deploy packaged applications into any J2EE-compliant container.

This article explains how to configure Eclipse and Lomboz to develop and deploy applications to OC4J.

What are the Prerequisites?

What Should You Know?

  • Be familiar with J2EE technologies (J2EE packaging and deployment, JSP).
  • Have some experience with Eclipse.

What are the Software Requirements?

What are the Notations?

  • %OC4J_HOME% - The directory you installed OC4J. Example: c:\oc4j
  • %JAVA_HOME% - The directory where your JDK is installed
  • %ECLIPSE_HOME% - The directory you installed Eclipse.

How to Build the Application

Installation and Configuration

Eclipse and Lomboz Installation

After you have downloaded and installed the Eclipse 3.0 IDE, follow these steps:

  1. Unzip EMF in the Eclipse directory ( %ECLIPSE_HOME% ).
  2. Unzip Lomboz 3.0.1 in the Eclipse directory. After you install (unzip) the plug-in, the directory structure looks like this:
  3. Copy the server definition files into the %ECLIPSE_HOME%\plugins\com.objectlearn.jdt.j2ee_3.0.1\servers\ directory. If you do not plan to use any other Application Server, then remove the different definition files.
  4. Run Eclipse.

The plug-in is now installed. To activate it, follow these steps:

  1. Choose the Window > Customize Perspective menu. This screen allows you to select the perspectives you want to be accessible directly from the different menus of the Eclipse IDE.
  2. In the Submenus list, select New . Then select all the Lomboz items to add the Lomboz elements to the File >New menu.
    Your perspectives screen should look like:
    custom perspective screen
  3. In the Submenu list, select Show View. Then select the Lomboz J2EE View to add the Lomboz view in your IDE.
  4. In the Commands tab, select Lomboz Actions to add the Lomboz button in the Eclipse toolbar. Use this button to switch the Lomboz J2EE View on and off.
  5. Click OK.

Eclipse Configuration

Configure the Label Decoration for Lomboz file

Lomboz provides J2EE decoration through the Eclipse Label Decorations (button??????). You can show additional information about an item on its label or icon. To activate J2EE decoration, following these steps:

  1. In the Eclipse menu, choose Window > Preferences.
  2. Open the Workbench node.
  3. Click Label Decorations.
  4. Select Lomboz J2EE Decorators.
Configure theJava Environment

By default, Eclipse uses a Java Runtime Environment (JRE). However, in the case of J2EE development ¾ especially for JSP compilation ¾ you must configure Eclipse to work with a Java Development Kit (JDK). To configure Eclipse to use the JDK, follow these steps:

  1. In the Eclipse menu, choose Window > Preferences.
  2. Open the Java node.
  3. Select the Installed JRE node.
  4. Click Add.
  5. In the Add JRE dialog box, first enter a name. Next, select the JDK home directory. Then click OK.
  6. Select the JDK 1.4.2 box to set this JDK as the default Java runtime. The Preferences screen looks like this:

Lomboz configuration

Lomboz is a set of wizards for J2EE development, testing, and deployment that makes it possible for you to deploy J2EE applications in different application servers. In the next steps, you will configure Lomboz and Eclipse to support OC4J deployment. You configure the Lomboz plug-in using the Eclipse preferences screen, used previously to set the JDK. If you have closed this window, click Window > Preferences.

Setting the JDK Tools

In the Preferences window, click Lomboz to set global settings.

  1. Select the JDK tools.jar file, based on the JDK installed on your system.
  2. Click Apply.
Configuring the Server Definition
  1. Select Server Definitions.
  2. Select "OC4J 10g (10.1.3) Developer Preview" in the server type.
  3. Enter the different values corresponding to your application server:
    • The OC4J Directory that is, %OC4J_HOME%
    • The username and password
    • The HTTP and ORMI ports
    • The default Web Site used by OC4J
  4. Click Apply.

The Preferences screen looks like this:

Lomboz Preferences Screen

The server definition is used to:

  • Put the necessary Java libraries in your project for compilation.
  • Run the container locally from Eclipse.
  • Deploy the application to your application server (locally or remotely).

Note: If you plan to deploy your application remotely, be sure that the release of the server you are using in Lomboz is identical to the one you are deploying on.

Web Module using Lomboz

First, create a J2EE Project using the Lomboz wizard.

Create the project

  1. In the Eclipse Workbench menu, choose File > New > Lomboz J2EE Project.
    New project
  2. Enter a name for your project for example, MyFirstJ2EEProject.

  3. Click Next. Keep all default on the Java Settings.

  4. Click Next.

  5. Click Add to add a new Web Module to your project.

  6. Enter the name of your J2EE Web Module for example, myWebApplication .

  7. Select the Targeted Servers tab.

  8. Add the OC4J release you are using.
    Select Targeted Servers

  9. Click Finish.

The Lomboz J2EE Project wizard creates the J2EE structure for the Web Module, as well as several additional files to build and deploy the application. The structure of the myWebApplication Web module looks like this:

Project Structure

You can now edit the JSP file using the Lomboz JSP Editor. This editor provides code-insight and checks the validity of the code.

Deploy the Application into OC4J

The next step in the development cycle is to test the application. To run the application inside OC4J, you must first package the application in an EAR file and then deploy it to your OC4J instance. The Lomboz plug-in for Eclipse enables you to package the application using a wizard and also to deploy the application to an OC4J instance.

Create a EAR Module

The first think to do is to create an EAR file that contains our Web module. Lomboz provides a wizard to help you to create and select the different modules to include in your EAR file.
  1. In the Eclipse menu select File > New > Lomboz EAR Module
  2. Enter the name and the description of your application:

    EAR File description

  3. Right Click, on the EAR Module and select Add Web Module
  4. Select the Web Module, myapp.war
  5. You can change the name of the WAR file, and the context-root.
  6. Select the web module you want to add to this EAR file by clicking on the button; the screen should look like:

     
  7. Select the Targeted Servers tab, and choose the OC4J release you are using.
  8. Click finish

Start the application server

If you are using a remote OC4J instance for deployment, then you do not need to follow these steps. However, you must ensure that the server is up before you deploy the application to it.

Lomboz allows you to start the targeted application server. You can do this from the Lomboz J2EE View, by right-clicking the server name and selecting Run Server .
Lomboz J2EE View
If you do not see the Lomboz J2EE view in the Eclipse IDE, you must activate the view by clicking on the Lomboz View icon Lomboz J2EE View Icon  in the toolbar or using the menu Window > Show View.

The OC4J instance directly starts from Eclipse, and OC4J uses the Console to print the information:

Eclipse Console With OC4J Log Message
 

Deploy The Application

Lomboz enables you to deploy applications directly from Eclipse. The OC4J server definition file provided in this document is configured to support deployment using the OC4J console tool (admin.jar ).

To deploy the application, right click on the EAR Module in the Lomboz view, named MyLombozApplication in our example, and choose Deploy.

The Lomboz deployment tool packages the Web application in a WAR file, creates the EAR file, and runs the OC4J Deployment tool. The Eclipse Console displays the messages returned by these different steps.

If you encounter a problem during deployment, please take a look to the known issues section.

Test The Application

You can now use the application from your browser using the URL: http://server:port/myapp

Known Issues

  • J2EEAction.Internal Error when deploying the Lomboz EAR Project: When Lomboz is packaging the EAR file, is validating the application.xml file using the default DTD ( http://java.sun.com/j2ee/dtds/application_1_2.dtd ). This error occurs when the DTD is not accessible.
    • If you do not have access to the Internet, you must delete the DTD declaration from the file. Using the Eclipse text editor, right-click the file, select Open with > Text Editor, and remove or comment the DOCTYPE declaration.
    • If you have access to the Internet using a proxy, you must set the proxy in the Eclipse preferences. To do this, in the Eclipse menu, click Window > Preferences. Then choose the Install/Update section, and set the proxy hostname and port.
  • Lomboz J2EE View is empty: Force the refresh of the view by resizing the view, or hide/show the view, using the Lomboz toolbar button .

If you encounter other issues, use the Eclipse log file for debugging. This file is located at:
%ECLIPSE_HOME%/workplace/.metadata

Summary

In this article you have learned how to:

  • Install the Lomboz plug-in into the Eclipse IDE.
  • Configure Lomboz to use OC4J.
  • Create a Web module using Lomboz wizards.
  • Package and deploy a J2EE application from Eclipse to OC4J.
  • Run a J2EE application in OC4J, in the context of Eclipse.
posted on 2005-08-22 21:13 Justin 阅读(3802) 评论(0)  编辑 收藏 引用 所属分类: Java
只有注册用户登录后才能发表评论。