1 2 3 4 Previous Next


58 posts

Bonjour, Comment Java?

This coming Thursday(08/27/09) 'll be at GooglePlex (Mountain View) for an Eclipse Day...The entire genda is at http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009.

2 presos seem to be very interesting so far:

and possibly others...The Google crowd is impressive.

There is a waiting list for people who did not register in time:-) But I am sure online videos of the conference will be available as well.

Ludo (Testing the new Java.net Blog system)






Worst ever Java EE 6 Blog Blog

Posted by ludo May 25, 2009

Bonjour, comment Java?

I'm preparing some Java EE 6 JavaOne demos. While doing that, I was thinking: how can I compress most of the Java EE 6 technology inside *one* single Java Class?
If you are my manager, stop reading now...
If you believe you are an architect, stop reading now...
If you are a member of the Java Blueprints team, stop reading now...
If you are a regular java blog reader, stop reading now...
The following code is PG 40. Talk to you parents if you are less than 40.

Still reading? Not sure why, but here we go.

The following Java EE 6 compliant Application is a Web Application with just 2 source files: MonsterServlet.java and persistence.xml.
It demonstrates the following Java EE 6 features:

  • Annotated Servlets 3.0, avoiding the need for web.xml!!!
  • EJB without local Interface: 100% POJO, and transactional (managed by the container) and securable
  • EJB inside a Web Application
  • JPA (still needs a persistence.xml ,  here it's defined as creating the tables at deploy time, assuming the database is already running)
  • EclipseLink Implementation
  • Default GlassFish v3 JavaDB database registered as "jdbc/__default" datasource.
  • Beans Validation framework (JSR 303...Merci Emmanuel)
  • Injection of EJBs inside a Servlet

Are you still reading? Remember the 3 tier architecture, with Data Layer, Business Layer, then Presentation Layer? Well forget it for this monster application  which merges all the layers into one single Java Class, which is a Servlet, an EJB and a Entity JPA bean validated with some Bean Validation annotations...

package monster;

import java.io.*;
import java.util.*;
import javax.ejb.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.persistence.*;
import javax.servlet.*;
import javax.validation.*;
import javax.validation.constraints.*;
* @author: Not Me!!!
@Stateless @Entity @WebServlet(urlPatterns = "/monster")
@Table(name = "MONSTERTABLE")
@NamedQueries({@NamedQuery(name = "MonsterEJB.findAll", query = "SELECT c FROM MonsterServlet c")})
@PersistenceContext(name = "monsterContext", unitName = "MonsterWebAppPU")
public class MonsterServlet extends HttpServlet {
    @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private int monsterId;
    @Max(2) @NotNull private String name;
    @Transient @EJB MonsterServlet monsterEJB;
   /*@Transient @PersistenceUnit(unitName = "MonsterWebAppPU") //does not work see EclipeLink bug
    private EntityManagerFactory emf;*/ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=277550
    public void doGet(HttpServletRequest request, HttpServletResponse response)
ServletException, IOException {
       response.getWriter().println("In Servlet calling the EJB side " + monsterEJB.EJBBusinessMethod("" + this));

    public String EJBBusinessMethod(String name) {
   try {
        InitialContext ic = new InitialContext();
        EntityManager em = (EntityManager) ic.lookup("java:comp/env/monsterContext");
       this.name = name;


        Query allMonsterQuery = em.createNamedQuery("MonsterEJB.findAll");
        List allMonsters = allMonsterQuery.getResultList();
        String error = validateTheMonsterJPA((MonsterServlet) allMonsters.get(0));
       return "BusinessMethod from EJB" + allMonsters.toString() + error;
    } catch (NamingException ex) {
      return "Error in EJBBusinessMethod "+ex.getMessage();

    private String validateTheMonsterJPA(MonsterServlet m) {
       String error=" ";
       ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
       Validator validator = factory.getValidator();
       Set<ConstraintViolation<MonsterServlet>> s = validator.validate(m);
      for (ConstraintViolation<MonsterServlet> c : s) {
            error = error+ " Contraint Violation: " + c.getMessage());
     return error;

And the persistence.xml to put in the WEB-INF/classes/META-INF directory of this Web Application

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="MonsterWebAppPU" transaction-type="JTA">
   <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

This Web Application can be deployed as it to the latest builds of GlassFish v3. The page output is something like:

In Servlet calling the EJB side BusinessMethod from EJB[monster.MonsterServlet@5718c3a7]  Contraint Violation: must be less than or equal to 2

Now the quiz:

  1. Explain the following statement: @Stateless @Entity @WebServlet
  3. what do you need to change in the code to remove the Contraint Violation statement in the output?
  5. Why do we need to inject the EJB aspect of this class into the servlet and cannot  just use "this" ?
  7. Do you think this bug will be fixed?  https://bugs.eclipse.org/bugs/show_bug.cgi?id=277550 

Still reading? Now I have just corrupted your brain: while not recommended, it is possible to write a 3-tier Java EE 6 Application with Servlets, EJBs, JPAs, Beans Validation in one single Java class and one single xml file...
Can't wait for Java EE 7 when persistence.xml will become optional:-)

See you at JavaOne. You can now forget this blog. Someone had to write it. It's over now:-)


GlassFish Tooling Blog

Posted by ludo May 21, 2009

Bonjour Comment Java?

Finally the GlassFish Tools bundle for Eclipse has been released: version 1.0 is available at http://download.java.net/glassfish/eclipse

The Tools bundle contains:

  • Eclipse 3.4.2 IDE with WTP Java EE support
  • GlassFish v2.1 pre-registered and configured
  • GlassFish v3 Prelude pre-registered and configured
  • JavaDB sample database pre-registered and configured
  • GlassFish Plugins
  • GlassFish documentation
  • And optionally, a JDK 1.6.

Installers are available for Windows and MacOSX, and tar.gz for Linux systems.
If you have used a preview release (pre version 1.0), make sure to read the release notes  http://download.java.net/glassfish/eclipse/releasenotes.html for information about a known issue regarding reusing workspaces created with preview releases. Commercial support for this bundle is also available at http://developers.sun.com/services/buying_guide.jsp.

I like the fact that the GlassFish servers are preconfigured, ready to use, even with a sample Java DB database pre registered (to use the JPA entities tooling). By default the "Deploy On Save" feature is enabled for GlassFish v3 Prelude: it means that the moment you save a Servlet, a utility class, or even an EJB, the application is automatically updated and redeployed to the running server in an optimal way. If you want to play with leading edge bits for GlassFish v3 Java EE 6, you can even register and download from the bundle a promoted build (happens every week) of the latest GlassFish v3 server. We will demo more about that at the JavaOne conference.

We are now working on a version 1.1 (and nightly builds will be available next week. Version 1.1 will add the OpenSolaris 2009.05 target, an optimized installer with Pack200 technology to reduce the download size by almost 2!, the JAX-WS and JAX-RS Jersey RestFul GlassFish Plugins, Maven 2, a MySQL JDBC driver pre registered for better out of the box experience with the MySQL database, the entire Java EE 6 Javadoc available in the Eclipse Editor code completion, and of course the latest bug fixes.

I hope to see you at JavaOne 2009.


EclipseCon GlassFish Slides Blog

Posted by ludo Mar 25, 2009

GlassFish and Eclipse Blog

Posted by ludo Mar 23, 2009

Bonjour Comment Java?

In a few hours, I'll be attending the EclipseCon Conference as a speaker. I've 2 talks, one around the GlassFish v2.1, v3 Prelude and GlassFish v3 Eclipse Bundle tooling (both for Java EE 5 and the coming Java EE 6) support, and the other one more targeted to GlassFish v3, its OSGi kernel (either Felix or Equinox) and some cool demos using Java EE features like EJBs inside a Web Application, or the new @Singleton or @Schedule timer annotations.

Also, this year, Sun Microsystems is a Gold Sponsor of the EclipseCon conference, so if you are around make sure you stop at our booths (GlassFish, OpenSolaris and JavaFX)
and see what has been done to better support Eclipse users.

q    e

Talk to you soon.

Bonjour, comment Java?

It has been said that GlassFish V3 Prelude could run with Eclipse Equinox OSGi implementation, but I could not find any real article on the web on how to setup this configuration. GlassFish V3 Prelude is bundled with Apache Felix OSGi implementation and this is the supported OSGi platform.The GlassFish community has also the honor and privilege of working directly with Richard Hall who recently joined Sun Microsystems.

But it does not mean we cannot try our runtime with other OSGi implementations to detect either bugs in our OSGi usage or bug in OSGi implementations:-).

Here are the steps to make the GlassFish v3 Prelude running on top of Equinox. There are still a few warnings in the log file that will be addressed soon I guess.

Download the fist Equinox zip file from http://download.eclipse.org/eclipse/equinox/
unzip this file under the GlassFish v3 Prelude directory. In my case this directory is C:/glassfishv3-prelude/glassfish
You should now see the following directory structure:

C:/glassfishv3-prelude/glassfish/eclipse/plugins/*.* jars

create  a new C:/glassfishv3-prelude/glassfish/eclipse/configuration directory and create a config.ini file in this configuration directory:
First lines of this file  need to be adapted to your installation directory:

# GlassFish required properties
# HK2 OSGi Adapter property

You are almost done. Now you need to configure the GlassFish v3 Prelude runtime to use Equinox instead of Felix. To do that, set the GlassFish_Platform environment variable:

On Windows, you can do  in a terminal:

set GlassFish_Platform=Equinox
On Mac OSx, you would do something like:
export GlassFish_Platform=Equinox

Now, from the  C:/glassfishv3-prelude/glassfish/bin directory, you can start the default domain:

.\asadmin start-domain --verbose

The server is starting...


And the welcome page can be seen:


There are still too many warnings in the console and I made Jerome aware of the issue. He told me that this will be fixed soon...

It would be nice to see how the other Application Servers based on OSGi framework handle OSGi implementation customization...Any links?



Jython 2.5 beta is out Blog

Posted by ludo Oct 31, 2008

Modern Economy Blog

Posted by ludo Oct 30, 2008

CommunityOne JavaOne 2008 Blog

Posted by ludo Apr 29, 2008

Filter Blog

By date: