Project Software Tools - University of Waterloo

26
Project Software Tools Getting Started with J2EE 1.4 ECE493-T5 Tiuley Alguindigue March 8 th ,2007

Transcript of Project Software Tools - University of Waterloo

Page 1: Project Software Tools - University of Waterloo

Project Software ToolsGetting Started with J2EE 1.4

ECE493-T5

Tiuley Alguindigue

March 8th,2007

Page 2: Project Software Tools - University of Waterloo

OverviewProject Software Environment (J2EE 1.4)

J2EE 1.4 Architecture and Installation

J2EE 1.4 Sun Java System Application Server PE 8.2

J2EE 1.4 Tutorial

Getting Started with Web Applications

Web Application Life CycleDemo hello1 sample deploymentAccesing Databases from Web Applications Apache Derby Database

The Duke’s Bank Application

Page 3: Project Software Tools - University of Waterloo

Project Software EnvironmentJ2EE 1.4

• We use J2EE1.4 - Java 2 Platform Enterprise Edition Technologies to develop a distributed application

• Note that the Java Platform Enterprise Edition – Java EE 5 is available and you can use this version for development but we will not be able to provide support for it.

Page 4: Project Software Tools - University of Waterloo

J2EE 1.4

• Allows you to build Distributed MultitieredWeb Applications

• There are two types of web applications:– Presentation Oriented (such as the course

project) – Service Oriented ( web services)

Page 5: Project Software Tools - University of Waterloo

J2EE 1.4

Page 6: Project Software Tools - University of Waterloo

J2EE 1.4Installation

You will need to download from the Sun web site at

http://java.sun.com/j2ee/1.4/download.html

1. J2EE 1.4 SDK 2. J2EE 1.4 Tutorial Update 7 (for Sun Java

System Application Server Platform Edition 8.2)

Page 7: Project Software Tools - University of Waterloo

J2EE 1.4 Verifiying your Installation

• From the Start menu, choose Programs => Sun Microsystems => Application Server PE=> Start Default Server.

• To verify that the server is running on your system, click this URL: http://localhost:8080.

Page 8: Project Software Tools - University of Waterloo

Sun Java System Application Server PE 8.2

• Fully compliant implementation of the J2EE 1.4 platform.

• Includes a number of tools to facilitate development. We will be talking about :

– Admin ConsoleA web-based GUI Application Server administration utility. Used tostop the Application Server and manage users, resources, and applications.

– deploytoolA GUI tool to package applications, generate deployment descriptors,and deploy applications on the Application Server.

– Derby database (PointBase database in earlier versions)A copy of the open source Derby database server.

Page 9: Project Software Tools - University of Waterloo

J2EE 1.4 TutorialPrerequisite

Java programming language

The Java™ Tutorial http://java.sun.com/docs/books/tutorial/

Relational database and JDBC

The Java™ TutorialTrail: JDBC(TM) Database Access

http://java.sun.com/docs/books/tutorial/jdbc

Page 10: Project Software Tools - University of Waterloo

J2EE 1.4 TutorialRelevant Reading

1 (Pages 2-9,13,18-19,22,24-30)Overview

J2EE Concepts, some APIs, and Sun Java System Application Server Platform

30 & 31Transactions and Resource connections

3Getting Started with Web Applications

23, 24, 25 & 26 (Required reading)Optional: 27, 28 & 29

Enterprise Java Beans

11, 12 & 13Servlets, Java Server Pages(JSPs) and Java Beans Components.

Chapters in J2EE 1.4 TutorialTechnology

Page 11: Project Software Tools - University of Waterloo

OverviewProject Software Environment (J2EE 1.4)

J2EE 1.4 Architecture and Installation

J2EE 1.4 Sun Java System Application Server PE 8.2

J2EE 1.4 Tutorial

Getting Started with Web Applications

Web Application Life CycleWeb ModulesDeployment DescriptorsDeployment ToolDemo hello1 sample deploymentAccesing Databases from Web Applications Apache Derby Database

The Duke’s Bank Application

Page 12: Project Software Tools - University of Waterloo

Getting Started with Web Applications

Page 13: Project Software Tools - University of Waterloo

Getting Started with Web Applications

• Web components

– Java servlets, JSP Pages

– Servlets are Java programming language classes that dynamically process requests and construct responses.

– JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content.

• Web Container

– Run time platform that provides services to web components.– Examples of these services are:

• Request dispaching• Security• Concurency• Life-cycle management

Page 14: Project Software Tools - University of Waterloo

Getting Started with Web Applications

Page 15: Project Software Tools - University of Waterloo

Web Application Life Cycle

1. Develop the web component code

2. Compile the web application components and helper classes referenced by the components

3. Package the application into a deployable unit

4. Deploy into a web container

5. Access url that references the ApplivcationWe’ll use the Deployment Tool for 3 and 4

Page 16: Project Software Tools - University of Waterloo

Web Modules

Page 17: Project Software Tools - University of Waterloo

Deployment Descriptors• An XML document that describes the deployment settings of an application

• There are two types of deployment descriptors: J2EE and runtime.

• A J2EE deployment descriptor is used to configure deployment settings on any J2EE-compliant implementation. The file is called web.xml.

• A runtime deployment descriptor is used to configure J2EE implementation-specific parameters. The file is called sun-moduleType.xml (ie. sun-web.xml)

ie. The runtime deployment descriptor for the Sun Application server has information such as:

• the context root of a web application, • the mapping of portable names of an application’s resources to the server’s resources,• Application Server implementation-specific parameters, such as caching directives.

• If you package the web application with deploytool, the deployment descriptors are created automatically

Page 18: Project Software Tools - University of Waterloo

Deployment Tool

• Used to package we application and to deploy to a web server.

• Web modules are packaged in WAR files.• EJBs are packaged in JAR files• A web application can consists of one or

several web modules and EJBs. Web applications are packaged in EAR files.

Page 19: Project Software Tools - University of Waterloo

Demo hello1 sample deployment

• Hello1 is a simple web module containing two JSPs and a gif file.

• We’ll show:– How to package it in a .war file– How to deploy it to a web server– How to update the jsp’s and redeploy to reflect

changes- How to deploy this web module without packaging in

war.- How to undeploy this application with deployment tool

Page 20: Project Software Tools - University of Waterloo

Accesing Databases from Web Applications

• JDBC API is used to access relational databases.

• Databases are accessed via DataSourceObjects with properties such as: – Database server– Database name– Network protocol used to connect to server

Page 21: Project Software Tools - University of Waterloo

Accesing Databases from Web Applications

• Web applications accessed a data source using a connection

• Data source objects may implement connection pooling to make applications run faster

• A connection is either a physical connection to the data source or a handle to a pooled connection if connection pooling is used.

• A data source is referred to as a JDBC resource

Page 22: Project Software Tools - University of Waterloo

Accesing Databases from Web Applications

Java Naming and Directory Interface(JNDI)• The Java Naming and Directory Interface(JNDI) naming

service enables components to locate other components and resources.

• For example, to locate a JDBC resource an enterprise bean invokes the JNDI lookup method.The JNDI naming service maintains a set of bindings that relate names to objects.The lookup method passes a JNDI name parameter and returns a related object.

• JNDI naming services allow customization of web components without changes to source code.

Page 23: Project Software Tools - University of Waterloo

Accesing Databases from Web Applications

• Show how:– Populate database– Create a data source in the Application Server

(Application Server Admin Console)– Specify a web application resource reference

(Deployment tool)– Map the resource reference to the data source

defined in the Aplication Server (Deployment tool)

Page 24: Project Software Tools - University of Waterloo

Accesing Databases from Web Applications

To create the connection to the database, the data access object database.BookDBAOlooks up the JNDI name of the bookstore data source object:

public BookDBAO () throws Exception {try { Context initCtx = new InitialContext();Context envCtx = (Context)

initCtx.lookup("java:comp/env");DataSource ds = (DataSource) envCtx.lookup("jdbc/BookDB");con = ds.getConnection();System.out.println("Created connection to database.");

} catch (Exception ex) {System.out.println("Couldn't create connection." + ex.getMessage());

throw new Exception("Couldn't open connection to database: "+ ex.getMessage());

}

Page 25: Project Software Tools - University of Waterloo

Apache Derby Database• Documentation at

http://db.apache.org/derby/manuals/index.html

• Ij tool C:\ECE493-T5\derbydemo>set

classpath=C:\Sun\AppServer\derby\lib\derbytools.jar;C:\Sun\AppServer\derby\lib\derby.jar;C:\Sun\AppServer\derby\lib\derbyclient.jar;C:\Sun\AppServer\derby\lib\derbynet.jar;C:\Sun\AppServer\derby\lib\derbytools.jar;

C:\ECE493-T5\derbydemo>java org.apache.derby.tools.ij

>java org.apache.derby.tools.ij

ij> connect 'jdbc:derby://localhost:1527/sun-appserv-samples';ij> select * from BOOKS;

Page 26: Project Software Tools - University of Waterloo

References

• J2EE 4.1 Tutorial