Book Image

Java EE Development with Eclipse

By : Deepak Vohra
Book Image

Java EE Development with Eclipse

By: Deepak Vohra

Overview of this book

<p>Java EE is the industry standard on enterprise computing and Oracle WebLogic Server is the most comprehensive platform for enterprise applications. The book combines Java EE with WebLogic Server in the most commonly used Java IDE, the Eclipse IDE 3.7.<br /><br />"Java EE Development with Eclipse" is the only book on Eclipse IDE for Java EE Developers. The book is a practical guide for using the most commonly used Java EE technologies and frameworks in Eclipse IDE. Sample applications are available in downloadable format and may be customized to meet requirements. Oracle Enterprise Pack for Eclipse 12c, an enhancement to Eclipse IDE, providing additional project facets and an integrated support for Oracle WebLogic Server is used.<br /><br />"Java EE Development with Eclipse" is based on developing applications with some of the commonly used technologies using the project facets in Eclipse 3.7 and its enhancement Oracle Enterprise Pack for Eclipse 12c. <br /><br />The book starts with a discussion on EJB 3.0 database persistence with Oracle database XE and Oracle WebLogic Server. JAXB is discussed in the context of bi-directional mapping between XML and Java. A generic web project is developed for PDF and Excel spread sheet reports. JavaServer Faces, the most commonly used view component in web applications is discussed for developing a data table. Facelets, which was integrated into JSF with 2.0 version is discussed in the context of templating. ADF Faces components are used to develop another user interface (UI) application. Web services are discussed with JAX-WS and JAX-RS technologies. Java EE frameworks Ajax and Spring are also discussed.</p>
Table of Contents (17 chapters)
Java EE Development with Eclipse
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Java Platform, Enterprise Edition (Java EE) 6 is the industry standard for enterprise Java computing. Eclipse IDE for Java EE developers is the most commonly used Java IDE for Java EE development. Eclipse IDE for Java EE developers supports Java EE 5 completely and also supports several features from Java EE 6.

The Oracle WebLogic Server product line is the industry's most comprehensive platform for developing, deploying, and integrating enterprise applications. Oracle Enterprise Pack for Eclipse provides a set of plugins (project facets) for Eclipse development with WebLogic Server.

While a number of books are available on Eclipse IDE for Java Developers, none or very few are available on Eclipse IDE for Java EE Developers. In this book, we shall discuss Java EE development in Eclipse IDE for Java EE developers. While it is not feasible to cover all of the more than 30 technologies in the Java EE stack (http://www.oracle.com/technetwork/java/javaee/tech/index.html), we shall discuss the most commonly used Java EE technologies, especially the ones Eclipse IDE for Java EE developers (or Oracle Enterprise Pack for Eclipse) provides Project for Facets. Oracle Enterprise Pack for Eclipse is just an enhancement of Eclipse IDE for Java EE developers with integrated support for Oracle WebLogic Server.

The objective of the book is to discuss how a developer would develop Java EE applications using commonly used Java EE technologies and frameworks in Eclipse IDE for Java EE developers. The book covers all aspects of application development including:

  • Setting the environment for an application

  • Using the Eclipse IDE wizards and the Component Palette

  • Running a sample application

What this book covers

Chapter 1, EJB 3.0 Database Persistence discusses creating an EJB project using the EJB 3.0 Module project facet. To create an entity bean, we add the JPA project facet. Subsequently, we generate entity beans from Oracle database tables. We create a session bean facade for the entity beans; wrapping an entity bean in a session bean facade is a best practice. We create a JSP client for the EJB application. We package and deploy the EJB application to Oracle WebLogic Server using an Ant build script and run the test client on the WebLogic Server.

Chapter 2, O/X Mapping with JAXB 2.x discusses the Object/XML (O/X) bi-directional mapping provided by the JAXB framework. We discuss the advantages of JAXB 2.x over JAXB 1.0. We create a JAXB web project using the JAXB project facet. We use the EclipseLink 2.4 persistence provider. We create an XML Schema and generate JAXB classes from the XML Schema using JAXB schema compilation. Subsequently, we marshall an XML document from a Java Document Object Model (DOM) document object, and also unmarshall an XML document using the compiled Java classes. We map an annotated Java class to an XML document using the annotations API. We also demonstrate the support for mapping Java classes to an XML Schema.

Chapter 3, Developing a Web Project for JasperReports demonstrates the use of the Oracle Enterprise Pack for Eclipse's integrated support for Oracle WebLogic Server to deploy and run any web application that requires an application server. First, we configure an Oracle database data source in WebLogic Server. We create and deploy a web application for JasperReports to the WebLogic Server, and subsequently run the web application to create PDF and Excel reports.

Chapter 4, Creating a JSF Data Table discusses how to use the JavaServer Faces project facet to create a JSF data table. First, we create a web project. Subsequently, we create a managed bean, create a JSF page, add a JSF data table to the JSF page, and run the JSF web application on the integrated WebLogic Server to create a JSF data table.

Chapter 5, Templating with Facelets discusses templating with Facelets. Templating is the use of a common "template", which is just an XHTML page, in Facelets' composition pages. Templating makes use of Facelets' header and footer pages for describing the common sections of Facelets' composition pages. WebLogic Server includes a shared library for JSF 2.0, which we configure first. We create a web project for Facelets, and create a managed bean to create a JSF data table. We add the 2.0 version of the JavaServer Faces project facet to the web project. For templating, we add a Facelets Template in which we configure the default sections of a Facelets composition page, a header, a content section, and a footer. We add Facelets composition pages for an SQL query input and a JSF Data Table output. We add the implicit navigation, a new feature in JSF 2.0. We run the Facelets application to demonstrate templating by including the same header and footer images in the input and output pages.

Chapter 6, Creating Apache Trinidad User Interfaces discusses the Trinidad project facet. Trinidad was formerly Oracle ADF Faces and provides a set of user interface components. First, we create a web project and add the Trinidad project facet to it. Subsequently, we create JSPs to create and find a catalog entry in Oracle database. We add Trinidad components to the JSP pages. We run the Trinidad application in the integrated WebLogic Server.

Chapter 7, Creating an AJAX Application discusses how to develop an AJAX application to send an asynchronous request to the server and receive a response from the server. The JavaScript project facet is enabled by default in a web project. The AJAX application is used to create a catalog entry in Oracle database by first validating the catalog ID using AJAX. The application is packaged, deployed, and run on the WebLogic Server.

Chapter 8, Creating a JAX-WS Web Service discusses how to use the Java API for XML web services (JAX-WS) to create a web service. First, we create a web service project, which has the Oracle WebLogic web service project facet associated with it. We test the web service on the server and generate a WSDL, which we test in the web explorer. We create a client class for the web service and package, then deploy and test the web service on the WebLogic Server.

Chapter 9, RESTful Web Services Using the JAX-RS API discusses RESTful web services using Java API for RESTful web services (JAX-RS), which are specified in the JSR 311 specification. We use the JAX-RS project facet for the RESTful web service. We create a Resource class, which is exposed as a URI path using the @PATH annotation. Subsequently, we create a Jersey Client API to test the web service.

Chapter 10, Spring discusses how to create a Spring framework application using the Spring project facet. We discuss method interception with a method interceptor and a Spring client. We also discuss Aspect Oriented Programming (AOP) in combination with JSF. We discuss creating a Spring bean, a bean definition file, and an AOP JavaBean.

What you need for this book

The book is based on Eclipse IDE for Java EE Developers version 3.7. We use the Oracle Enterprise Pack for Eclipse packaged Eclipse IDE with integrated support for Oracle WebLogic Server 12c, which may be downloaded from http://www.oracle.com/technetwork/middleware/ias/downloads/wls-main-097127.html. We have used the Oracle Database Express Edition 11g Release 2, which can be downloaded from http://www.oracle.com/technetwork/products/express-edition/overview/index.html.

Some other chapter specific software such as JasperReports is also required. We have used the Windows version, but if you have Linux installed the book may still be used (though the source code and samples have not been tested with Linux). Slight modifications may be required with the Linux Install; for example, the directory paths on Linux would be different than the Windows directory paths used in the book. You need to install J2SE 5.0 or later.

Who this book is for

The target audience of the book is Java EE application developers who want to learn about the practical use of Eclipse IDE for application development. This book is suitable for professional Java EE developers. The book is also suitable for an intermediate/advanced level course in Java EE development. The target audience is expected to have prior, albeit beginner's, knowledge about Java EE, Enterprise JavaBeans (EJB) 3.0, entity and session EJBs, JavaServer Faces (JSF), ADF Faces, AJAX, web services, and Spring framework. The book also requires some familiarity with WebLogic Server and Eclipse IDE.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The catalog.xsd Schema gets parsed and compiled."

A block of code is set as follows:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.example.org/catalog" xmlns:catalog="http://www.example.org/catalog"
  elementFormDefault="qualified">
  <xsd:element name="catalog" type="catalog:catalogType" />
  <xsd:element name="catalogid" type="xsd:int" />
  <xsd:complexType name="catalogType"> [default]

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.example.org/catalog" xmlns:catalog="http://www.example.org/catalog"
  elementFormDefault="qualified">
  <xsd:element name="catalog" type="catalog:catalogType" />

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.

Copyright Credits

Some of the contents of this book were originally published by Oracle Technology Network and http://home.java.net/. They are republished with the permission of Oracle Corporation.