Full download Java EE 7 Development with NetBeans 8 3rd Edition David R. Heffelfinger pdf docx
Full download Java EE 7 Development with NetBeans 8 3rd Edition David R. Heffelfinger pdf docx
https://ebookfinal.com/download/java-ee-5-development-using-glassfish-
application-server-1st-ed-edition-david-r-heffelfinger/
https://ebookfinal.com/download/java-ee-development-with-eclipse-2nd-
edition-ram-kulkarni/
https://ebookfinal.com/download/beginning-ejb-3-java-ee-7-edition-
jonathan-wetherbee/
https://ebookfinal.com/download/jasperreports-reporting-for-java-
developers-1st-edition-david-heffelfinger/
Java EE 7 Recipes A Problem Solution Approach 1st Edition
Josh Juneau (Auth.)
https://ebookfinal.com/download/java-ee-7-recipes-a-problem-solution-
approach-1st-edition-josh-juneau-auth/
https://ebookfinal.com/download/java-concepts-compatible-with-
java-5-6-and-7-6th-edition-cay-s-horstmann/
https://ebookfinal.com/download/java-ee-6-pocket-guide-1st-edition-
arun-gupta/
https://ebookfinal.com/download/the-java-ee-5-tutorial-2nd-ed-edition-
eric-jendrock/
https://ebookfinal.com/download/beginning-java-java-7-edition-ivor-
horton-ivor-horton/
Java EE 7 Development with NetBeans 8 3rd Edition
David R. Heffelfinger Digital Instant Download
Author(s): David R. Heffelfinger
ISBN(s): 9781783983520, 1783983523
Edition: 3
File Details: PDF, 22.73 MB
Year: 2015
Language: english
www.allitebooks.com
Java EE 7 Development
with NetBeans 8
David R. Heffelfinger
BIRMINGHAM - MUMBAI
www.allitebooks.com
Java EE 7 Development with NetBeans 8
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78398-352-0
www.packtpub.com
www.allitebooks.com
Credits
Reviewers Proofreaders
Saurabh Chhajed Ting Baker
Halil Karaköse Simran Bhogal
Mario Pérez Madueño Samuel Redman Birch
David Salter Maria Gould
Manjeet Singh Sawhney Ameesha Green
Paul Hindle
Acquisition Editor
Bernadette Watkins
Sam Wood
Indexer
Content Development Editors
Tejal Soni
Madhuja Chaudhari
Anand Singh Production Coordinator
Aparna Bhagat
Technical Editor
Pramod Kumavat Cover Work
Aparna Bhagat
Copy Editors
Roshni Banerjee
Neha Karnani
www.allitebooks.com
About the Author
www.allitebooks.com
About the Reviewers
Saurabh Chhajed is a Cloudera Certified Developer for Apache Hadoop and Sun
(Oracle) Certified Java/J2EE Programmer with 5 years of professional experience in
the enterprise application development life cycle using the latest frameworks, tools,
and design patterns. He has extensive experience of working with Agile and Scrum
methodologies and enjoys acting as an evangelist for new technologies such as NoSQL
and big data and analytics. Saurabh has helped some of the largest U.S. companies to
build their product suites from scratch. While not working, he enjoys traveling and
sharing his experiences on his blog (http://saurzcode.in).
He has worked in the telecommunications industry for 10 years, and has worked
for Turkcell and Ericsson. In 2014, he quit his job at Ericsson to establish his own
software consultancy company, KODFARKI (http://kodfarki.com).
His primary focus is Java, Java EE, Spring, and Primefaces. He also likes to give Java
trainings. He has a keen interest in Java tools that speed up development, such as
NetBeans and IntelliJ IDEA. In his spare time, he likes running, skiing, and playing
PES.
www.allitebooks.com
Mario Pérez Madueño was born in 1975 in Turin and lives in Barcelona. He
graduated in computer engineering from the Open University of Catalonia (UOC),
Spain, in 2010. Mario is a Java SE, ME, and EE enthusiast and has been a member of
the NetBeans Community Acceptance Testing program (NetCAT) for many years.
He was also the technical reviewer of the books, Java EE 5 Development with NetBeans
6 and Building SOA-based Composite Applications Using NetBeans IDE 6, both by
Packt Publishing.
I would like to thank my wife, María, for her unconditional help and
support in all the projects I get involved in, and Martín and Matías
for giving me the strength to go ahead.
David Salter is an enterprise software developer and architect who has been
developing software professionally since 1991. His relationship with Java goes back
to the beginning, when Java 1.0 was used to write desktop applications and applets
for interactive websites. David has been developing enterprise Java applications
using both Java EE (and J2EE) and open source solutions since 2001. David wrote
the books, NetBeans IDE 8 Cookbook and Seam 2.x Web Development, both by Packt
Publishing. He has also co-authored the book, Building SOA-Based Composite
Application Using NetBeans IDE 6, Packt Publishing.
www.allitebooks.com
Manjeet Singh Sawhney currently works for a large IT consultancy in
London, UK, as a Principal Consultant - Enterprise Data Architect within the
Global Enterprise Architecture Consulting practice. Previously, he worked for
global organizations in various roles, including development, technical solutions
consulting, and data management consulting. Although Manjeet has worked across
a range of programming languages, he specializes in Java. During his postgraduate
studies, he also worked as a Student Tutor for one of the top 100 universities in the
world, where he was teaching Java to undergraduate students and was involved
in marking exams and evaluating project assignments. Manjeet acquired his
professional experience by working on several mission-critical projects serving
clients in the financial services, telecommunications, manufacturing, retail, and
public sectors.
www.allitebooks.com
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
TM
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
www.allitebooks.com
Table of Contents
Preface 1
Chapter 1: Getting Started with NetBeans 7
Introduction 7
Obtaining NetBeans 9
Installing NetBeans 12
Microsoft Windows 12
Mac OS X 12
Linux 13
Other platforms 13
Installation procedure 13
Starting NetBeans for the first time 20
Configuring NetBeans for Java EE development 21
Integrating NetBeans with a third-party application server 22
Integrating NetBeans with a third-party RDBMS 25
Adding a JDBC driver to NetBeans 26
Connecting to a third-party RDBMS 27
Deploying our first application 30
NetBeans tips for effective development 33
Code completion 33
Code templates 37
Keyboard shortcuts 40
Understanding NetBeans visual cues 44
Accelerated HTML5 development support 46
Summary 51
www.allitebooks.com
Table of Contents
[ ii ]
Table of Contents
[ iii ]
Table of Contents
[ iv ]
Preface
Java EE 7, the latest version of the Java EE specification, adds several new features
to simplify enterprise application development. New versions of existing Java EE
APIs have been included in this latest version of Java EE. JSF 2.2 has been updated
to better support wizard-like interfaces via FacesFlows and has been enhanced to
better support HTML5. NetBeans supports JPA 2.1 features such as Bean Validation
and many others. EJB session beans can be automatically generated by NetBeans,
allowing us to easily leverage EJB features such as transactions and concurrency.
CDI advanced features such as qualifiers, stereotypes, and others can be easily
implemented via NetBeans' wizards. JMS 2.0 has been greatly simplified, allowing us
to quickly and easily develop messaging applications. Java EE includes a new Java
API for JSON Processing (JSON-P), allowing us to quickly and easily process JSON
data. NetBeans includes several features to allow us to quickly and easily develop
both RESTful and SOAP-based web services.
This book will guide you through all the NetBeans features that make the
development of enterprise Java EE 7 applications a breeze.
Chapter 2, Developing Web Applications Using JavaServer Faces 2.2, explains how
NetBeans can help us easily develop web applications that take advantage of the
JavaServer Faces 2.2 framework.
Preface
Chapter 3, JSF Component Libraries, covers how NetBeans can help us easily develop
JSF applications using popular component libraries such as PrimeFaces, RichFaces,
and ICEfaces.
Chapter 4, Interacting with Databases through the Java Persistence API, explains how
NetBeans allows us to easily develop applications taking advantage of the Java
Persistence API (JPA), including how to automatically generate JPA entities from
existing schemas. This chapter also covers how complete web-based applications
can be generated with a few clicks from an existing database schema.
Chapter 5, Implementing the Business Tier with Session Beans, discusses how NetBeans
simplifies EJB 3.1 session bean development.
Chapter 6, Contexts and Dependency Injection, discusses how the CDI API introduced
in Java EE 6 can help us integrate the different layers of our application.
Chapter 7, Messaging with JMS and Message-driven Beans, explains Java EE messaging
technologies such as the Java Message Service (JMS) and Message-driven Beans
(MDB), covering NetBeans' features that simplify application development taking
advantage of these APIs.
Chapter 8, Java API for JSON Processing, explains how to process JSON data using the
new JSON-P Java EE API.
Chapter 9, Java API for WebSocket, explains how to use the new Java API for
WebSocket to develop web-based applications featuring full duplex communication
between the browser and the server.
Chapter 10, RESTful Web Services with JAX-RS, covers RESTful web services with
the Java API for RESTful Web Services, including coverage of how NetBeans can
automatically generate RESTful web services and both Java and JavaScript RESTful
web service clients.
Chapter 11, SOAP Web Services with JAX-WS, explains how NetBeans can help us
easily develop SOAP web services based on the Java API for the XML Web Services
(JAX-WS) API.
[2]
Preface
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"NetBeans uses the JAVA_HOME environment variable to populate the JDK's
directory location."
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.flow.FlowScoped;
import javax.inject.Named;
@Named
@FlowScoped("registration")
public class RegistrationBean {
...
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
package com.ensode.flowscope.namedbeans;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.flow.FlowScoped;
import javax.inject.Named;
@Named
@FlowScoped("registration")
public class RegistrationBean {
...
[3]
Preface
New terms and important words are shown in bold. Words that you see on the
screen, for example, in menus or dialog boxes, appear in the text like this: " To
download NetBeans, we need to click on the Download button."
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it
helps us develop titles that you will really get the most out of.
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 at 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.
[4]
Preface
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 could 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/submit-errata, 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 copyrighted 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.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at
[email protected], and we will do our best to address the problem.
[5]
Getting Started with
NetBeans
In this chapter, we will learn how to get started with NetBeans. The following topics
are covered in this chapter:
• Introduction
• Obtaining NetBeans
• Installing NetBeans
• Starting NetBeans for the first time
• Configuring NetBeans for Java EE development
• Deploying our first application
• NetBeans tips for effective development
Introduction
NetBeans is an Integrated Development Environment (IDE) and platform.
Although initially, the NetBeans IDE could only be used to develop Java
applications, as of version 6, NetBeans supports several programming languages,
either through built-in support, or by installing additional plugins. Programming
languages natively supported by NetBeans include Java, C, C++, PHP, HTML, and
JavaScript. Groovy, Scala, and others are supported via additional plugins.
Some of the features we will cover include how NetBeans can help us speed up
web application development using JavaServer Faces (JSF), the standard Java EE
component based web framework by providing a starting point for these kinds of
artifacts. We will also see how NetBeans can help us generate Java Persistence API
(JPA) entities from an existing database schema (JPA is the standard object-relational
mapping tool included with Java EE).
[8]
Chapter 1
Obtaining NetBeans
NetBeans can be obtained by downloading it from http://www.netbeans.org.
[9]
Getting Started with NetBeans
[ 10 ]
Chapter 1
To follow the examples in this book, either the Java EE or the All bundle is needed.
The screenshots in this book were taken with the Java EE bundle.
NetBeans may look slightly different if the All bundle is used,
particularly, some additional menu items might be seen.
• Windows
• Linux (x86/x64)
• Mac OS X
The NetBeans download page should detect the operating system being used to
access it, and the appropriate platform should be selected by default. If this is not
the case, or if you are downloading NetBeans with the intention of installing it in
another workstation on another platform, the correct platform can be selected from
the drop down labeled appropriately enough as Platform.
Once the correct platform has been selected, we need to click on the appropriate
Download button for the NetBeans bundle we wish to install; for Java EE
development, we need either the Java EE, or the All bundle. NetBeans will
then be downloaded to a directory of our choice.
[ 11 ]
Getting Started with NetBeans
Installing NetBeans
NetBeans requires a Java Development Kit (JDK) Version 1.7 or newer to be
available before it can be installed.
NetBeans installation varies slightly between the supported platforms. In the following
few sections we explain how to install NetBeans on each supported platform.
Microsoft Windows
For Microsoft Windows platforms, NetBeans is downloaded as an executable
file named something like netbeans-8.0-javaee-windows.exe (exact name
depends on the version of NetBeans and the NetBeans bundle that was selected
for download). To install NetBeans on Windows platforms, simply navigate to the
folder where NetBeans was downloaded and double-click on the executable file.
Mac OS X
For Mac OS X, the downloaded file is called something like netbeans-8.0-javaee-
macosx.dmg (exact name depends on the NetBeans version and the NetBeans bundle
that was selected for download). In order to install NetBeans, navigate to the location
where the file was downloaded and double-click on it.
[ 12 ]
Chapter 1
Linux
For Linux, NetBeans is downloaded in the form of a shell script. The name of the file
will be similar to netbeans-8.0-javaee-linux.sh (exact name will depend on the
version of NetBeans and the selected NetBeans bundle).
Other platforms
For other platforms, NetBeans can be downloaded as a platform independent ZIP
file. The name of the ZIP file will be something like netbeans-8.0-201403101706-
javaee.zip (exact filename may vary, depending on the exact version of NetBeans
downloaded and the NetBeans bundle that was selected).
To install NetBeans on one of these platforms, simply extract the ZIP file to any
suitable directory.
Installation procedure
Even though the way to execute the installer varies slightly between platforms, the
installer behaves in a similar way between most of them.
[ 13 ]
Getting Started with NetBeans
After executing the NetBeans installation file for our platform, we should see a
window similar to the one illustrated in the following screenshot.
The pack shown may vary depending on the NetBeans bundle that was downloaded.
The preceding screenshot is for the Java EE bundle.
At this point, we should click on the button labeled Next> to continue the installation.
[ 14 ]
Chapter 1
NetBeans is dual licensed, licenses for NetBeans include the GNU Public License
(GPL) Version 2 with the classpath exception, and the Common Development and
Distribution License (CDDL). Both of these licenses are approved by the Open
Source Initiative (OSI).
To continue installing NetBeans, click on the checkbox labeled I accept the terms in
the license agreement and click on the button labeled Next>.
[ 15 ]
Getting Started with NetBeans
NetBeans comes bundled with JUnit, a popular Java unit testing framework. JUnit's
license differs from the NetBeans license, so it needs to be accepted separately.
Clicking the Next> button takes us to the next step in the installation wizard:
At this point the installer will prompt us for a NetBeans installation directory, and
for a JDK to use with NetBeans. We can either select new values for these or retain
the provided defaults.
Once we have selected the appropriate installation directory and JDK, we need to
click on the button labeled Next> to continue the installation.
[ 16 ]
Chapter 1
The installer will now prompt us for an installation directory for the GlassFish
application server, as well as for the JDK to use for GlassFish; we can either enter
a custom directory or accept the default values and then click on Next>.
[ 17 ]
www.allitebooks.com
Getting Started with NetBeans
If we chose to install Tomcat, the installer will prompt us for a Tomcat installation
directory. Again, we can either enter a custom directory or accept the default values
and then click on Next>.
At this point, the installer will display a summary of our choices. After reviewing the
summary, we need to click on the button labeled Install to begin the installation.
[ 18 ]
Chapter 1
As the installation begins, the installer starts displaying a progress bar indicating the
progress of installation.
After NetBeans and all related components have been installed, the installer indicates
a successful installation, giving us the option to contribute anonymous usage data as
shown in the preceding screenshot. After making our selection we can simply click
on the Finish button to exit the installer.
On most platforms, the installer places a NetBeans icon on the desktop; the icon
should look like the following:
[ 19 ]
Getting Started with NetBeans
Once NetBeans starts, we should see a page with links to demos, tutorials, and
sample projects, among others.
[ 20 ]
Chapter 1
Every time NetBeans is launched, it shows the default start page as illustrated in the
preceding screenshot. If we don't want this page to be displayed automatically every
time NetBeans is started, we can disable this behavior by un-checking the checkbox
labeled as Show on Startup at the top of the page. We can always get the start page
back by going to Help | Start Page.
[ 21 ]
Getting Started with NetBeans
[ 22 ]
Chapter 1
2. Next, we need to right-click on the node labeled Servers in the tree inside
the Services window, and then select Add Server... from the resulting
pop-up menu.
3. Then we need to select the server to install from the list in the resulting
window, and click on the button labeled Next>.
[ 23 ]
Getting Started with NetBeans
5. Finally, we need to select a domain, host, and port for our application server,
then click on the Finish button.
[ 24 ]
Chapter 1
The Services window should now display our newly added application server:
[ 25 ]
Getting Started with NetBeans
We then need to select a JAR file containing the JDBC driver for our RDBMS,
NetBeans guesses the name of the driver class containing the JDBC driver. If more
than one driver class is found in the JAR file, the correct one can be selected from the
drop-down menu labeled Driver Class. We need to click on the OK button to add
the driver to NetBeans as shown in the following screenshot:
[ 26 ]
Chapter 1
Once we have followed the preceding procedure, our new JDBC driver is displayed
in the list of registered drivers.
To connect to our third-party RDBMS, we need to right-click on its driver under the
Services tab, then click on Connect Using... on the resulting pop-up menu as shown
in the following screenshot:
[ 27 ]
Exploring the Variety of Random
Documents with Different Content
and Loli, and Kohenemonemo Loli, ame ka laua wahine o
the wife of the two men. Kohenemonemo.
Hauna and his younger brother O Hauna nae ame kona kaikaina
Loli, the personal attendants or me Loli, na kahu hoi o ua o
retainers of Lonoikamakahiki, Lonoikamakahiki, he mau kaula
were prophets; they were men laua, he mau kanaka haipule
who paid attention strictly to the hoi, a ua oleloia he mau kanaka
laws of the gods, and it was said mana laua, a he hiki ia laua ke
that they were men who hana i na hana mana he nui ma
possessed supernatural powers, ka inoa o ko Keawenuiaumi
and that they were able to akua, ame ko laua akua hoi.
perform many miracles in the
name of the god of
Keawenuiaumi, and also in the
name of their own god.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com