<Insert Picture Here>

Java EE 6 application development, OSGi and Eclipse users
Roberto Chinnici
Java EE 6 Specification Lead
Ludovic Champenois, GlassFish Tools Architect
JAVA EE 6
FINAL RELEASE
DECEMBER 10, 2009
What's New?

•
•
•
•
•

Several new APIs
Web Profile
Pluggability/extensibility
Dependency injection
Lots of improvements to existing APIs
New and updated components

•
•
•
•
•
•
•
•
•

EJB 3.1
JPA 2.0
Servlet 3.0
JSF 2.0
JAX-RS 1.1
Connectors 1.6
Bean Validation 1.0
DI 1.0
CDI 1.0

•
•
•
•
•
•
•
•
•

Managed Beans 1.0
Interceptors 1.1
JAX-WS 2.2
JSR-109 1.3
JSP 2.2
EL 2.2
JSR-250 1.1
JASPIC 1.1
JACC 1.5
Web Profile

• First Java EE profile to be defined
• A fully-functional, mid-size stack for modern web
application development
• Complete, but not the kitchen sink
Java EE 6 Web Profile Contents

JSF 2.0
JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0
Servlet 3.0
EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0
Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1
JPA 2.0 · JTA 1.1
Pluggability/Extensibility

• Focus on the web tier in this release
• Create a level playing field for third-party frameworks
• Simplify packaging of web applications
Modular Web Applications

•
•
•
•
•
•

Libraries can contain /META-INF/web-fragment.xml
web.xml is optional
@WebServlet, @WebFilter annotations
ServletContainerInitializer interface
Programmatic registration of components
Resource jars containing /META-INF/resources
Sample Web Fragment Descriptor
<web-fragment
version=”3.0”
xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>welcome</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<listener>
<listener-class>RequestListener</listener-class>
</listener>
</web-fragment>
JAX-RS 1.1

•
•
•
•
•

RESTful web services API
Already widely adopted
Really a general, high-level HTTP API
Annotation-based programming model
Programmatic API when needed
JAX-RS Sample
@Path(“widgets/{id}”)
@Produces(“application/widgets+xml”)
public class WidgetResource {
public WidgetResource(@PathParam(“id”)
String id) {…}
@GET
public Widget getWidget() {…}
@PUT
public void putWidget(Widget widget){…}
}
Bean Validation 1.0

• Integrated with JSF, JPA
• Declarative constraints using annotations
@NotNull
@Size(max=40) String address;
• Fully extensible: define your own constraints
@Email String recipient;
• Validator API for programmatic validation
validator.validate(obj) → Set<ConstraintViolation>
EJB 3.1

• @Singleton beans
• @Startup beans
• @Asynchronous invocations
@Asynchronous public Future<Integer> compute();
• Define EJBs directly inside a web application
• EJBContainer API works on Java SE
Adding an EJB to a Web Application
Before
BuyBooks.war

ShoppingCart
EJB Class

Now
ShoppingCart
EJB Class

ShoppingCart.jar

BuyBooks.ear

BuyBooks.war
Dependency Injection

• DI + CDI (JSR-330 + JSR-299)
• @Resource still around
@Resource DataSource myDB;
• Added @Inject annotation for typesafe injection
@Inject @LoggedIn User user;
• Automatic scope management (request, session, etc.)
• No configuration: beans discovered at startup
• Extensible via the BeanManager API
Dependency Injection Sample
@ApplicationScoped
public class CheckoutHandler {
@Inject
public CheckoutHandler(
@LoggedIn User user,
@Reliable @PayBy(CREDIT_CARD)
PaymentProcessor processor,
@Default ShoppingCart cart) {…}
}

Injection points identified by Qualifier + Type
@Default can be omitted
JSF 2.0

•
•
•
•
•
•

Facelet as a standard view declaration language
Composite components
Automatic discovery of component libraries
Programmatic and declarative Ajax support
System events
Validation out-of-the-box
Java EE 6 Platform

•
•
•
•

More powerful
More flexible
More extensible
Easier to use

http://java.sun.com/javaee
What is GlassFish
• A Community
– Users, Partners, Testers, Developers
– Started in 2005 on http://java.net

• Application Server
– Enterprise Quality and Open Source (CDDL & GPL v2)
– Java EE 5 / 6 Reference Implementation

• Full Commercial Support from Oracle
– Not only a Reference Implementation
– Roadmap announced tomorrow regarding HA, Clustering...
GlassFish v3...
• The Java EE 6 spec, of course, and...
• Beyond the spec
– Fast, very fast, small, very small
– restart, btrace/dtrace, embedded, modularity, OSGi, RESTful
Admin,...
– Scripting: jRoR, Grails, and now Django

• Update Center: repository of new/updated bundles
• Tooling: Netbeans 6.8, IntelliJ,vi, and
– Eclipse 3.5, 3.6Mx
Modular and Dynamic
• Modular : OSGi: Equinox and Apache Felix
• But also Equinox or Static mode, thanks to HK2
– Yet very Fast !

• Painless Java EE 6 development
–
–
–
–

Via the new/easier APIs
Via better tools integration
Ultra fast Auto-deploy of all Java EE and static artifacts
Application runner
• java -jar glassfish.jar foo.war
Web Session Retention
• Deployment option to maintain stateful sessions across redeployments
– $ asadmin redeploy --properties keepSessions=true myapp.war
– Enabled by Default in Eclipse IDE

• For All sessions:
– Servlets, CDIs, Stateful EJBs,...

• Greatly simplifies the development paradigm
GlassFish and OSGi
• GlassFish runs on top of OSGi (Felix and Equinox)
– GlassFish ships with 200+ bundles

• Can use OSGi management tools (CLI or Web)
• Any OSGi bundle will run in GlassFish v3
– Drop it in domain1/autodeploy/bundles
– Can also asadmin deploy it using --type osgi

• Consume OSGi services via @Resource
@Resource (mappedName="MYPUREOSGISERVICE")

HelloService

myOSGiService;

• Web Application Bundle (WAB Support)
Demo
• GlassFish Java EE dev in Eclipse
Integration with maven 2
• Java EE 6 APIs in Maven repository
– http://download.java.net/maven/2/javax/javaee-api/
– Stripped jars: very small <1Mb
– Not to be used for Testing

• GlassFish Embbeded can run via Maven
– mvn gf:run
Update Center: Add/Remove/Update Bundles
Thanks for your attention!
• http://java.sun.com/javaee
• http://glassfish.org

Java EE 6, Eclipse, GlassFish @EclipseCon 2010

  • 1.
    <Insert Picture Here> JavaEE 6 application development, OSGi and Eclipse users Roberto Chinnici Java EE 6 Specification Lead Ludovic Champenois, GlassFish Tools Architect
  • 2.
    JAVA EE 6 FINALRELEASE DECEMBER 10, 2009
  • 3.
    What's New? • • • • • Several newAPIs Web Profile Pluggability/extensibility Dependency injection Lots of improvements to existing APIs
  • 4.
    New and updatedcomponents • • • • • • • • • EJB 3.1 JPA 2.0 Servlet 3.0 JSF 2.0 JAX-RS 1.1 Connectors 1.6 Bean Validation 1.0 DI 1.0 CDI 1.0 • • • • • • • • • Managed Beans 1.0 Interceptors 1.1 JAX-WS 2.2 JSR-109 1.3 JSP 2.2 EL 2.2 JSR-250 1.1 JASPIC 1.1 JACC 1.5
  • 5.
    Web Profile • FirstJava EE profile to be defined • A fully-functional, mid-size stack for modern web application development • Complete, but not the kitchen sink
  • 6.
    Java EE 6Web Profile Contents JSF 2.0 JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0 Servlet 3.0 EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0 Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1 JPA 2.0 · JTA 1.1
  • 7.
    Pluggability/Extensibility • Focus onthe web tier in this release • Create a level playing field for third-party frameworks • Simplify packaging of web applications
  • 8.
    Modular Web Applications • • • • • • Librariescan contain /META-INF/web-fragment.xml web.xml is optional @WebServlet, @WebFilter annotations ServletContainerInitializer interface Programmatic registration of components Resource jars containing /META-INF/resources
  • 9.
    Sample Web FragmentDescriptor <web-fragment version=”3.0” xmlns="http://java.sun.com/xml/ns/javaee"> <servlet> <servlet-name>welcome</servlet-name> <servlet-class>WelcomeServlet</servlet-class> </servlet> <listener> <listener-class>RequestListener</listener-class> </listener> </web-fragment>
  • 10.
    JAX-RS 1.1 • • • • • RESTful webservices API Already widely adopted Really a general, high-level HTTP API Annotation-based programming model Programmatic API when needed
  • 11.
    JAX-RS Sample @Path(“widgets/{id}”) @Produces(“application/widgets+xml”) public classWidgetResource { public WidgetResource(@PathParam(“id”) String id) {…} @GET public Widget getWidget() {…} @PUT public void putWidget(Widget widget){…} }
  • 12.
    Bean Validation 1.0 •Integrated with JSF, JPA • Declarative constraints using annotations @NotNull @Size(max=40) String address; • Fully extensible: define your own constraints @Email String recipient; • Validator API for programmatic validation validator.validate(obj) → Set<ConstraintViolation>
  • 13.
    EJB 3.1 • @Singletonbeans • @Startup beans • @Asynchronous invocations @Asynchronous public Future<Integer> compute(); • Define EJBs directly inside a web application • EJBContainer API works on Java SE
  • 14.
    Adding an EJBto a Web Application Before BuyBooks.war ShoppingCart EJB Class Now ShoppingCart EJB Class ShoppingCart.jar BuyBooks.ear BuyBooks.war
  • 15.
    Dependency Injection • DI+ CDI (JSR-330 + JSR-299) • @Resource still around @Resource DataSource myDB; • Added @Inject annotation for typesafe injection @Inject @LoggedIn User user; • Automatic scope management (request, session, etc.) • No configuration: beans discovered at startup • Extensible via the BeanManager API
  • 16.
    Dependency Injection Sample @ApplicationScoped publicclass CheckoutHandler { @Inject public CheckoutHandler( @LoggedIn User user, @Reliable @PayBy(CREDIT_CARD) PaymentProcessor processor, @Default ShoppingCart cart) {…} } Injection points identified by Qualifier + Type @Default can be omitted
  • 17.
    JSF 2.0 • • • • • • Facelet asa standard view declaration language Composite components Automatic discovery of component libraries Programmatic and declarative Ajax support System events Validation out-of-the-box
  • 18.
    Java EE 6Platform • • • • More powerful More flexible More extensible Easier to use http://java.sun.com/javaee
  • 20.
    What is GlassFish •A Community – Users, Partners, Testers, Developers – Started in 2005 on http://java.net • Application Server – Enterprise Quality and Open Source (CDDL & GPL v2) – Java EE 5 / 6 Reference Implementation • Full Commercial Support from Oracle – Not only a Reference Implementation – Roadmap announced tomorrow regarding HA, Clustering...
  • 21.
    GlassFish v3... • TheJava EE 6 spec, of course, and... • Beyond the spec – Fast, very fast, small, very small – restart, btrace/dtrace, embedded, modularity, OSGi, RESTful Admin,... – Scripting: jRoR, Grails, and now Django • Update Center: repository of new/updated bundles • Tooling: Netbeans 6.8, IntelliJ,vi, and – Eclipse 3.5, 3.6Mx
  • 22.
    Modular and Dynamic •Modular : OSGi: Equinox and Apache Felix • But also Equinox or Static mode, thanks to HK2 – Yet very Fast ! • Painless Java EE 6 development – – – – Via the new/easier APIs Via better tools integration Ultra fast Auto-deploy of all Java EE and static artifacts Application runner • java -jar glassfish.jar foo.war
  • 23.
    Web Session Retention •Deployment option to maintain stateful sessions across redeployments – $ asadmin redeploy --properties keepSessions=true myapp.war – Enabled by Default in Eclipse IDE • For All sessions: – Servlets, CDIs, Stateful EJBs,... • Greatly simplifies the development paradigm
  • 24.
    GlassFish and OSGi •GlassFish runs on top of OSGi (Felix and Equinox) – GlassFish ships with 200+ bundles • Can use OSGi management tools (CLI or Web) • Any OSGi bundle will run in GlassFish v3 – Drop it in domain1/autodeploy/bundles – Can also asadmin deploy it using --type osgi • Consume OSGi services via @Resource @Resource (mappedName="MYPUREOSGISERVICE") HelloService myOSGiService; • Web Application Bundle (WAB Support)
  • 25.
    Demo • GlassFish JavaEE dev in Eclipse
  • 26.
    Integration with maven2 • Java EE 6 APIs in Maven repository – http://download.java.net/maven/2/javax/javaee-api/ – Stripped jars: very small <1Mb – Not to be used for Testing • GlassFish Embbeded can run via Maven – mvn gf:run
  • 27.
  • 28.
    Thanks for yourattention! • http://java.sun.com/javaee • http://glassfish.org