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?
- OracleAS Containers for J2EE 10g (9.0.4 Production or 10.1.3 Developer Preview) available from OTN.
- Sun's JDK 1.4_x, available here
- Eclipse IDE 3.0 available on the Eclipse Web site
- Lomboz 3.0.1, available for download from the Object Learn Web site. (download page)
- Eclipse Modeling Framework (EMF) plug-in, available from the Lomboz download page.
- Lomboz Server Definitions for OC4J. To download them, right-click any of the following links, then choose Save link as:
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:
- Unzip EMF in the Eclipse directory ( %ECLIPSE_HOME% ).
- Unzip Lomboz 3.0.1 in the Eclipse directory. After you install (unzip) the plug-in, the directory structure looks like this:
- 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.
- Run Eclipse.
The plug-in is now installed. To activate it, follow these steps:
- 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.
- 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:
- In the Submenu list, select Show View. Then select the Lomboz J2EE View to add the Lomboz view in your IDE.
- 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.
- 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:
- In the Eclipse menu, choose Window > Preferences.
- Open the Workbench node.
- Click Label Decorations.
- 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:
- In the Eclipse menu, choose Window > Preferences.
- Open the Java node.
- Select the Installed JRE node.
- Click Add.
- In the Add JRE dialog box, first enter a name. Next, select the JDK home directory. Then click OK.
- 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.
- Select the JDK tools.jar file, based on the JDK installed on your system.
- Click Apply.
Configuring the Server Definition
- Select Server Definitions.
- Select "OC4J 10g (10.1.3) Developer Preview" in the server type.
- 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
- Click Apply.
The Preferences screen looks like this:
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
- In the Eclipse Workbench menu, choose File > New > Lomboz J2EE Project.
-
Enter a name for your project for example, MyFirstJ2EEProject.
-
Click Next. Keep all default on the Java Settings.
-
-
Click Add to add a new Web Module to your project.
-
Enter the name of your J2EE Web Module for example, myWebApplication .
-
Select the Targeted Servers tab.
-
Add the OC4J release you are using.
-
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:
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.
- In the Eclipse menu select File > New > Lomboz EAR Module
- Enter the name and the description of your application:
- Right Click, on the EAR Module and select Add Web Module
- Select the Web Module, myapp.war
- You can change the name of the WAR file, and the context-root.
- Select the web module you want to add to this EAR file by clicking on the button; the screen should look like:
- Select the Targeted Servers tab, and choose the OC4J release you are using.
- 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 .
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
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:
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.