Using Sun Microsystems' J2EE SDK

Before you can start coding real J2EE applications, you need a J2EE implementation and a Java development environment, such as Sun Microsystems JDK or a Java Integrated Development Environment (IDE). This book uses the Sun Microsystems' J2EE SDK, which is a complete reference implementation of J2EE. It includes all the classes, containers, and tools you need to learn J2EE.

To run the example code provided on the CD-ROM accompanying this book, you will also need to install a sample database. Installing the sample database is described in the Exercise at the end of this day's lesson. But now, to give you some hands-on work before you study the theory behind J2EE, you will install the J2EE SDK 1.3 on your workstation.

Note

The J2EE SDK is free to download, use for learning J2EE, and use as a development tool. The Sun Microsystems license for this product states that you may not use it in a production environment. Be warned!


Installing J2EE SDK 1.3

Before you download the SDK, ensure that you have J2SE 1.3.1_01 (also known as JDK 1.3.1) or later correctly installed and are using one of the following supported platforms:

  • Windows NT4 or 2000

  • Solaris SPARC 7 or 8

  • Linux Redhat v 6.0 or 6.1

You can use a Java IDE that supports J2SE 1.3 (or later) in preference to the Sun Microsystem's J2SE JDK 1.3.1.

Before installing J2EE SDK 1.3, you must uninstall any previous versions of the J2EE SDK.

Finally, you must ensure that you have a JAVA_HOME environment variable that points to the location of the directory where you installed J2SE SDK (or your preferred Java IDE). This should have been defined when you (or your administrator) installed the J2SE SDK (JDK). If the JAVA_HOME variable is not defined, you must define it now as follows.

If you are using Windows NT or 2000 (remember J2EE SDK is not supported on other Windows' platforms) you should set the JAVA_HOME variable in your system environment so that it is defined for all of the programs you run. Do this using the Control Panel as follows:

1.
Within the Control Panel, select System.

2.
The System Properties dialog appears, select the Advanced tab.

3.
Click Environment Variables.

4.
The Environment Variables dialog appears, click New.

5.
The New System Variable dialog appears, enter the name and value of the variable. Assuming that you installed the J2EE SDK 1.3 on the C: drive using the default directory name, you will set the JAVA_HOME variable to

C:j2sdkee1.3

6.
Click OK to clear each of the dialogs.

You must have administrator privileges to edit or change system environment variables. If you do not have administrator privilege, you can still use the JDK, but you'll have to define the variables in your user environment. Any other users of your workstation will also have to define the same variables in their environment.

If you are using Linux or Unix and the JAVA_HOME environment variable does not exist, you can set it with the following command(you must be using the Bourne, Korn, Bash or compatible shell):

JAVA_HOME=/usr/local/jdk1.3.1
export JAVA_HOME

This example assumes you have installed the Sun Microsystems' JDK 1.3.1 in /usr/local.

Typically, you will add these variable definitions to your login environment by adding the same two lines to the.profile file in your home directory.

Finally, you should ensure that the JDK bin directory is in your search path (again this should already be configured on your workstation).

For Windows users, if your search path does not contain the JDK bin directory, add the following directory to your PATH via the Control Panel:

%JAVA_HOME%in

For Linux/Unix users, if your search path does not contain the JDK bin directory, add the following line to your .profile file:

PATH=$PATH:$JAVA_HOME/bin

Now download the J2EE SDK in the format appropriate to your system from http://java.sun.com/j2ee/sdk_1.3/index.html. You should download the J2EE SDK to a temporary directory because the installation process will ask you where to install the SDK.

The installation of the SDK is quite straightforward; just follow the instructions for your platform:

  • WindowsDouble-click the icon of the j2sdkee-1_3_01-win.exe file and follow the onscreen instructions.

  • SolarisIssue the following commands to make the download bundle executable and run the installation::

    chmod a+x ./j2sdkee-1_3__01-solsparc.sh
    ./j2sdkee-1_3__01-solsparc.sh
    
  • Linux— Change directories to the required parent directory for the J2EE SDK (for example, /usr/local) and extract the download bundle using the following command:

    tar – xzvf <download_directory>/j2sdkee-1_3_01-linux.tar.gz
    

Now you must:

  1. Define the J2EE_HOME variable.

  2. Add the J2EE SDK bin directory to your search path.

  3. Add the J2EE classes to your CLASSPATH.

You have already been shown how to define variables and change your path for your environment (Windows users use the Control Panel and Linux/Unix users add variable definition lines to .profile), so making these changes will be straightforward.

Windows users must (assuming the J2EE SDK was installed on the C: drive)

  1. Define the following environment variable

    J2EE_HOME=c:j2eesdk1.3
    
  2. Add the following directory to the end of the PATH variable:

    %J2EE_HOME%in
    
  3. Add the J2EE JAR files to the CLASSPATH variable:

    %J2EE_HOME%libj2ee.jar;%J2EE_HOME%liblocale
    

    If your CLASSPATH variable is not currently defined, you must ensure that it includes the current directory so the full setting will be

    .;%J2EE_HOME%libj2ee.jar;%J2EE_HOME%liblocale
    

Linux/Unix users must add the following to their .profile (assuming the J2EE SDK was installed in /usr/local/j2eesdk1.3):

  1. Define the following environment variable:

    J2EE_HOME=/usr/local/j2eesdk1.3
    
  2. Update the PATH variable for J2EE SDK:

    PATH=$PATH:$J2EE_HOME/bin
    
  3. Add the J2EE JAR files to the CLASSPATH variable:

    CLASSPATH=$CLASSPATH:$J2EE_HOME/lib/j2ee.jar:$J2EE_HOME/lib/locale
    

    If your CLASSPATH variable is not currently defined, you must ensure that it includes the current directory so the full setting will be:

    CLASSPATH=.:$J2EE_HOME/lib/j2ee.jar:$J2EE_HOME/lib/locale
    

That is it! You are now ready to start using the J2EE SDK.

Note

All the documentation for the J2EE utility programs and class files is contained in the J2EE SDK download bundle. You will find the documentation in the docs sub-directory of the J2EE installation directory.


Starting the J2EE Reference Implementation (RI)

The J2EE SDK includes a Reference Implementation of J2EE. This Reference Implementation (RI) contains the following software programs:

  • A J2EE server

  • A relational database called Cloudscape

  • An HTTP (Web) server

  • A JNDI service implementation

  • A JMS service implementation

  • Class files for the J2EE APIs

  • Various administration and support utilities

The server software components of the RI (database, JNDI, Web server, and J2EE server) are purely for development and are not designed for commercial use. The J2EE RI has been used for the code shown in this book because it is free of charge and conforms to the J2EE 1.3 specification.

To develop J2EE applications and run the example code presented in this book, you will need to start the J2EE server and the Cloudscape database server. Starting the J2EE server will also start the JNDI, JMS, and HTTP servers provided with the J2EE RI.

There are no graphic tools for managing the J2EE and Cloudscape servers, so you will have to start them from the command line. Each server should be started in a separate command window or Telnet window if you are not using a graphical console. It does not matter in which order you start the J2EE and Cloudscape servers.

In the following examples, you must have configured your search path (the PATH environment variable) to include the J2EE SDK bin directory as shown previously.

To start the J2EE RI server, create a new window with access to a command-line prompt (command window for Windows NT/2000 or a terminal or shell window for Linux/Unix users). Enter the following command at the prompt:

j2ee –verbose

This will start the J2EE server in the current window with diagnostic messages displayed in the window. If (or when) you have problems deploying your J2EE applications to the server, it is this window you should examine for error messages. If you put simple diagnostic messages in your EJBs that write to System.out or System.err, these messages will also appear in this window.

Listing 2.1 shows the diagnostic messages issued as the J2EE RI and associated servers startup.

Listing 2.1. Successful J2EE Reference Implementation Startup Diagnostics
   1: > j2ee -verbose
   2: J2EE server listen port: 1050
   3: Naming service started:1050
  4: Binding DataSource, name = jdbc/DB2, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
   5: Binding DataSource, name = jdbc/DB1, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
   6: Binding DataSource, name = jdbc/InventoryDB, url = jdbc:cloudscape:rmi
:CloudscapeDB;create=true
   7: Binding DataSource, name = jdbc/Cloudscape, url = jdbc:cloudscape:rmi
:CloudscapeDB;create=true
   8: Binding DataSource, name = jdbc/EstoreDB, url = jdbc:cloudscape:rmi
:CloudscapeDB;create=true
   9: Binding DataSource, name = jdbc/XACloudscape, url = jdbc/XACloudscape__xa
  10: Binding DataSource, name = jdbc/XACloudscape__xa, dataSource =    COM.cloudscape
.core.RemoteXaDataSource@653220
  11: Starting JMS service...
  12: Initialization complete - waiting for client requests
  13: Binding: < JMS Destination : jms/Queue , javax.jms.Queue >
  14: Binding: < JMS Destination : jms/firstQueue , javax.jms.Queue >
  15: Binding: < JMS Destination : jms/Topic , javax.jms.Topic >
  16: Binding: < JMS Cnx Factory : QueueConnectionFactory , Queue , No properties >
  17: Binding: < JMS Cnx Factory : jms/QueueConnectionFactory , Queue , No properties >
  18: Binding: < JMS Cnx Factory : TopicConnectionFactory , Topic , No properties >
  19: Binding: < JMS Cnx Factory : jms/TopicConnectionFactory , Topic , No properties >
  20: Starting web service at port: 8000
  21: Starting secure web service at port: 7000
  22: J2EE SDK/1.3
  23: Starting web service at port: 9191
  24: J2EE SDK/1.3
  25: J2EE server startup complete.
						

If you start the J2EE server without the -verbose option, all the diagnostic messages will be written to log files in the logs sub-directory of the J2EE SDK installation directory. You will find additional logging information is also written to these log files even with the -verbose option specified.

The J2EE log files are stored in a sub-directory named after your workstation in the logs sub-directory of the J2EE SDK installation directory. Further sub-directories are used to separate the log files for the J2EE, JMS, and HTTP servers.

To start up the Cloudscape database server, you must open a new window and enter the following command:

cloudscape –start

Again, some simple diagnostic messages will be displayed as the server starts up, as shown in Listing 2.2.

Listing 2.2. Successful Cloudscape Startup Diagnostics
> cloudscape -start
Thu Jan 10 10:52:18 GMT+00:00 2002: [RmiJdbc] Starting Cloudscape RmiJdbc Server
 Version 1.7.2 ...
Thu Jan 10 10:52:25 GMT+00:00 2002: [RmiJdbc] COM.cloudscape.core.JDBCDriver registered in
 DriverManager
Thu Jan 10 10:52:25 GMT+00:00 2002: [RmiJdbc] Binding RmiJdbcServer
Thu Jan 10 10:52:25 GMT+00:00 2002: [RmiJdbc] No installation of RMI Security Manager
Thu Jan 10 10:52:26 GMT+00:00 2002: [RmiJdbc] RmiJdbcServer bound in rmi registry
						

Troubleshooting J2EE and Cloudscape

You should have no problems starting up either server. If you do have problems, check the error messages displayed in the relevant window. The most likely problems are discussed in the rest of this section.

Read Only Installation Directory

You will not be able to run J2EE RI and Cloudscape unless you have installed the J2EE SDK in a writeable directory. If you have installed the J2EE SDK as a privileged user (Administrator, root, or whomever), make sure that you grant your normal login account read and write permission to the installation directory and all contained files and directories.

Server Port Conflicts

Although the J2EE SDK software uses TCP port numbers that are not normally used by other software, there is always a possibility that there will be a port number conflict.

If a port is used by another software server, a J2EE component will fail to start up and you will see an error message stating that the server “Could not connect to a required port.” The error will normally include a stack trace.

The most likely cause of a port conflict is where you (or another developer) have already started the J2EE server. Listing 2.3 shows the error message for this situation.

Listing 2.3. Error Message Caused by Running the J2EE Server Twice
> j2ee -verbose
J2EE server listen port: 1050
org.omg.CORBA.INTERNAL:   minor code: 1398079697  completed: No
at com.sun.corba.ee.internal.iiop. GIOPImpl.createListener(GIOPImpl.java:256)
        at com.sun.corba.ee.internal.iiop. GIOPImpl.getEndpoint(GIOPImpl.java:205)
        at com.sun.corba.ee.internal.iiop. GIOPImpl.initEndpoints(GIOPImpl.java:140)
        at com.sun.corba.ee.internal.POA.POAORB. getServerEndpoint(POAORB.java:488)
        at com.sun.corba.ee.internal.POA.POAImpl. pre_initialize(POAImpl.java:154)
        at com.sun.corba.ee.internal.POA.POAImpl.<init>(POAImpl.java:112)
        at com.sun.corba.ee.internal.POA.POAORB.makeRootPOA(POAORB.java:110)
        at com.sun.corba.ee.internal.POA.POAORB$1.evaluate(POAORB.java:128)
        at com.sun.corba.ee.internal.core.Future.evaluate(Future.java:21)
at com.sun.corba.ee.internal.corba.ORB. resolveInitialReference(ORB.java:2421)
        at com.sun.corba.ee.internal.corba.ORB. resolve_initial_references(ORB.java:2356)
        at com.sun.enterprise.server.J2EEServer.run(J2EEServer.java:193)
        at com.sun.enterprise.server.J2EEServer.main(J2EEServer.java:913)

java.lang.RuntimeException: Unable to create ORB. Possible causes include TCP/IP ports in
 use by another process
        at com.sun.enterprise.server.J2EEServer.run(J2EEServer.java:203)
        at com.sun.enterprise.server.J2EEServer.main(J2EEServer.java:913)
java.lang.RuntimeException: Unable to create ORB. Possible causes include TCP/IP ports in
 use by another process
        at com.sun.enterprise.server.J2EEServer.run(J2EEServer.java:203)
        at com.sun.enterprise.server.J2EEServer.main(J2EEServer.java:913)

java.lang.RuntimeException: Unable to create ORB. Possible causes include TCP/IP ports in
 use by another process
        at com.sun.enterprise.server.J2EEServer.run(J2EEServer.java:350)
        at com.sun.enterprise.server.J2EEServer.main(J2EEServer.java:913)
J2EE server reported the following error: Unable to create ORB. Possible causes include
 TCP/IP ports in use by another process
Error executing J2EE server ...
							

You cannot run more than one J2EE RI server on the same workstation.

If your port conflict is with another piece of software, try to disable this software when running J2EE RI and Cloudscape. If this is not possible, you can change the port numbers used by each J2EE server by editing the file called server.xml in the conf sub-directory of the J2EE SDK installation directory. The definitions of the default server port numbers are obvious if you are used to reading and editing XML files. Changing the J2EE RI port numbers is something you should avoid if at all possible.

Applications Failing with a “Connection Refused: no further information” Exception

A common error when working with the J2EE RI is to forget to start up the Cloudscape database server in a separate window. If you fail to start the database and use a J2EE component, such as an EJB, that accesses the database, you will get the following error:

java.sql.SQLException: Connection refused to host: <hostname>; nested exception is:
java.net.ConnectException: Connection Refused: no further information

To solve this problem, start up the Cloudscape server as described previously and stick a note to your monitor to remind you to start the database as well as J2EE. If you are confident with batch or shell scripts, you can write your own scripts to start both servers in separate windows.

The following simple scripts will work for the indicated platforms:

On Windows NT/2000, use

start "J2EE" j2ee –verbose
start "Cloudscape" cloudscape –start

On Solaris, use

dtterm –name j2ee –e "j2ee –verbose" &
dtterm –name cloudscape –e "cloudscape –start" &

On Linux, use

xterm –title j2ee –e "j2ee –verbose" &
xterm –title cloudscape –e "cloudscape –start" &
							

Closing Down J2EE RI and Cloudscape

To close down J2EE RI and Cloudscape, you should use the following commands:

j2ee –stop
cloudscape –stop

These commands can be run from any command window. Remember that the J2EE and Cloudscape server windows are busy and cannot accept additional commands while the servers are running.

Although Sun Microsystems do not recommend this approach, typing ^C (Ctrl+C) in the server window or simply closing the window will also shut down the servers.

Optional Software Used in this Book

A Java IDE (JDK) and a J2EE implementation (J2EE SDK) are all you require to learn how to develop J2EE applications. However, areas of this book look at using J2EE applications in a wider context and make use of additional (freely available) software.

So that you are aware of this software, Table 2.1 lists the optional software used in this book. Full instructions for downloading and configuring this software (should you want to do so) are included in the relevant day's instructions. You do not need to download this software at the present time.

Table 2.1. Optional Software Used in Daily Lessons
Day Software Resource URL
3 OpenLDAP and a Unix system to run the Open LDAP server. http://www.openldap.org/software/download/
14 JSPTL Java Standard Tag libraries from the Apache Jakarta project. http://jakarta.apache.org/taglibs/index.html
17 XALAN from the Apache project. http://xml.apache.org/xalan-j/index.html
20 Apache Axis alpha2. http://xml.apache.org/axis/index.html
 Apache Tomcat 4.0.1. http://jakarta.apache.org/tomcat/index.html
 JAXM 1.0 reference implementation (part of the “JAX Pack Fall 01”). http://java.sun.com/xml

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.42.128