Instant Developer Experience

The Embedded GlassFish Web Plugin allows you to create an Instant Developer Experience for your web application. In essence, this means that starting development is extremely easy. It also reduces staff turnover costs tremendously, which is especially good news for Open Source projects. Reducing the barriers to entry makes it easier for people to contribute.

Characteristics of an Instant Developer Experience are:

  • Minimal requirements for the development environment
  • The source code is fully self-contained and has no external dependencies

The Instant Developer Experience itself consists of:

  1. Getting the source code (you cannot work without it)
  2. Execute the single build command mentioned in the file README.txt, e.g.:
    mvn glassfish:run
  3. Login into the application using the URL and credentials mentioned in README.txt.

As you can see, it is trivially easy to start development. This is intended. You can see the application working, and correlate what you see with the source code. And the source code is sufficient, as there are no outside dependencies.

The development environment

Preparing a development environment for an Instant Developer Experience mostly consists of leaving stuff out. This is what you need:

  • Java
  • A build tool (Maven or something equally powerful)
  • Your favorite IDE

    That's is. No database, no application server, no servlet container, etc. Just the three items above.

Creating an Instant Developer Experience

Creating an Instant Developer Experience means that your project sources must be organized a little differently that you're used to. This has little to do with the structure: migrating from Ant to Maven is a lot more work. What we need to do is to make our sources fully self-contained.

This means:

  • Setup our build tool to both compile the sources and start a container.
  • When our build tool starts a container, it should also start any services our application depends on. This may be a database, mailserver, etc.

If you're using Maven, the first part is easy: just configure your pom.xml to use the Embedded GlassFish Web Plugin.

The second part is only slightly more difficult, depending on your needs. The most common two services an application depends on are a database (RDBMS) and SMTP server.

For a mailserver, you can use the Wiser Framework from SubEtha SMTP. To use it, your application must only connect to the mailserver to actually send email. Your integration tests then ensure the mailserver is running as needed, so they can examine the mail that was sent. This is the dependency you'll need to add to your pom.xml:

<dependency>
        <groupId>org.subethamail</groupId>
        <artifactId>subethasmtp-wiser</artifactId>
        <version>1.2</version>
</dependency>

A database is slightly work. Not setting up the database: that's simply adding dependency to e.g. HsqlDB, and (assuming Maven with the Embedded GlassFish Web Plugin mentioned above), defining a DataSource to a JDBC URL like jdbc:hsqldb:mem:test. The tricky part is ensuring that the database has content after starting the application. For the persistence framework of GlassFish, EclipseLink, there is no ready-made solution yet, but you can create a javax.servlet.ServletContextListener to populate your database. As an added bonus, you can also annotate it with javax.servlet.annotation.WebListener to have GlassFish automatically pick it up to populate your database. This means that the class can be in the test classpath, and it will not be deployed to production.