2.introduction To Support For Java EE Technology in NetBeans IDE
2.introduction To Support For Java EE Technology in NetBeans IDE
NetBeans IDE has been developed in close cooperation with the Java EE and GlassFish teams to provide the
tightest integration and easiest possible use of the Java EE specification. NetBeans IDE is the best way to quickly
learn and become productive in Java EE programming.
This document provides an introduction to the major concepts of the Java EE specifications and how they relate to
your hands-on programming. The following topics are covered:
Web Services
You can find more information about developing and deploying Java EE applications in the Java EE 7 Tutorial and
the Java EE 6 Tutorial.
Annotations are marked with a @character. In the IDE, when you create a type that makes use of annotations in Java
EE, related placeholders are provided in the generated code. For example, when you use the IDE to create a
stateless session bean, the following code is generated, which includes the @Stateless()annotation:
package mypackage;
import javax.ejb.*;
@Stateless()
public class HelloWorldSessionBean implements mypackage.HelloWorldSessionLocal {
Code completion provides access to annotation attributes specific to the item under the cursor. For example, when
you press Ctrl-Space in the brackets of a @WebService()annotation, you see the following:
Each attribute has default values. Therefore, you do not need to specify any attributes unless you want to use a value
other than the default value. In simple cases, the default value is sufficient, which means that you do not even need
to provide attributes at all.
Fewer required classes and interfaces. You no longer need home and object interfaces for EJB
components because the container is now responsible for exposing the necessary methods. You only need
to supply a business interface. You can use annotations to declare your EJB components and the container
will manage the transactions.
No more deployment descriptors. You can use annotations directly in the class to tell the container about
dependencies and configuration that you formerly defined in deployment descriptors. If there are no specific
instructions, the container uses default rules to handle the most common situations.
Simple lookups. The EJBContextenables you to lookup objects in the JNDI name space directly in the
class.
Simplified object-relational mapping. The new Java Persistence API makes object-relational mapping much
simpler and transparent by allowing you to use annotations in POJOs to map Java objects to relational
databases.
In the IDE, you can code enterprise beans just as you would code other Java classes, using code completion and
editor hints to implement the correct methods and keep the classes in synch with their interfaces. You do not need to
use special commands and dialog boxes to generate things like business methods or web service operations,
although the commands are still available to help acquaint you with the syntax of Java EE code.
To request injection of a resource, a component uses the @Resourceannotation or, in the case of some
specialized resources, the @EJBand @WebServiceRefannotations. Resources that can be injected include:
SessionContextobject
DataSourcesobject
EntityManagerinterface
Web services
In the IDE, the Source Editor provides full code completion for resources injection annotations provided by the Java
EE platform. In addition, the IDE automatically injects resources into your files when you run commands like Call EJB
and Use Database.
Entities are POJOs. Unlike EJB components that used container-managed persistence (CMP), entity objects
using the new APIs are no longer components, and they no longer need to be in an EJB module.
Standardized object-relational mapping. The new specification standardizes how object-relational mapping
is handled, freeing the developer from learning vendor-specific strategies. The Java Persistence API uses
annotations to specify object-relational mapping information, but still support XML descriptors.
Named queries. A named query is now a static query expressed in metadata. The query can be either a Java
Persistence API query or a native query. This makes reusing queries very simple.
Simple packaging rules. Because entity beans are simple Java technology classes, they can be packaged
virtually anywhere in a Java EE application. For example, entity beans can be part of an EJB JAR, application-
client JAR, WEB-INF/lib, WEB-INF/classes, or even part of a utility JARin an enterprise application
archive (EAR) file. With these simple packaging rules, you no longer have to make an EAR file to use entity
beans from a web application or application client.
Detached entities. Because entity beans are POJOs, they can be serialized and sent across the network to a
different address space and used in a persistence-unaware environment. As a result, you no longer need to
use data transfer objects (DTOs).
EntityManager API. Application programmers now use a standard EntityManager API to perform Create
Read Update Delete(CRUD) operations that involve entities.
The IDE provides tools to work with the new Java Persistence API. You can generate entity classes automatically
from a database, or code entity classes by hand. The IDE also provides templates and graphic editors for creating
and maintaining persistence units. See Getting Started with Java EE Applications for more information on using the
Java Persistence API.
Web Services
In the Java EE platform, the use of annotations has greatly improved and simplified web services support. The
following specifications contributed to this area: JSR 224, Java API for XML-Based Web Services (JAX-WS) 2.0; JSR
222, Java Architecture for XML Binding (JAXB) 2.0; and JSR 181, Web Services Metadata for the Java Platform.
JAX-WS 2.0
JAX-WS 2.0 is the new API for web services in the Java EE platform. As a successor to JAX-RPC 1.1, JAX-WS 2.0
retains the natural RPC programming model while improving on several fronts: data binding, protocol and
transport independence, support for the RESTstyle of web services, and ease of development.
A crucial difference from JAX-RPC 1.1 is that all data binding has now been delegated to JAXB 2.0. This allows
JAX-WS-based web services to use 100 percent of XML Schema, which results in improved interoperability and
ease of use. The two technologies are well integrated, so users no longer have to juggle two sets of tools. When
starting from Java technology classes, JAXB 2.0 can generate XML Schema documents that are automatically
embedded inside a Web Service Description Language (WSDL) document, saving users from performing this
error-prone integration manually.
Out of the box, JAX-WS 2.0 supports the SOAP 1.1, SOAP 1.2, and XML/HTTP protocols. Protocol extensibility has
been a goal from the very beginning, and JAX-WS 2.0 allows vendors to support additional protocols and
encodings for better performance -- for example, the FAST Infoset -- or for specialized applications. Web services
that use attachments to optimize the sending and receiving of large binary data can take advantage of the
MTOM/XOP (short for message transmission optimization mechanism/XML-binary optimized packaging)
standard from W3C without any adverse effect on the programming model. (See this page for information on
MTOM/XOP.) Before Java EE technology, defining a web service required long, unwieldy descriptors. Now it's as
easy as placing the @WebServiceannotation on a Java technology class. All the public methods on the class
are automatically published as web service operations, and all their arguments are mapped to XML Schema
data types using JAXB 2.0.
Asynchronous methods can be used in conjunction with any WSDL-generated interfaces as well as with the
more dynamic DispatchAPI. For your convenience, when importing a WSDL document, you can require
asynchronous methods to be generated for any of the operations defined by the web service.
In the polling model, you make a call. When you're ready, you request the results.
In the callback model, you register a handler. As soon as the response arrives, you are notified.
Note that asynchronous invocation support is entirely implemented on the client side, so no changes are
required to the target web service.
The IDE provides tools to work with JAX-WS. You can use templates in the New File wizard to generate JAX-WS
artifacts. Asynchronous web services can be created by means of a Web Service Customization editor. The code
completion functionality includes annotations that you can use in your web services.
Next Steps
For more information about using NetBeans IDE to develop Java EE applications, see the following resources:
To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans
IDE Java EE development features, join the nbj2ee@netbeans.org mailing list.