Platform specific resource binding

One of the most obvious problems of running your application anywhere is determining how your Java EE application can use application server resources.

Always use resource references is the best choice to start with. Not only will you prevent a hard link between application and runtime configuration, but jndi namespace bindings can typically cause problems. 

Binding deployment descriptors are a way to facilitate easy deployment in your IDE environment. Both JBoss as well as Glassfish and WebSphere make use of these binding files. This also implies that if you want to develop applications on JBoss as well as WebSphere, that you will need to supply both sets of binding files.

So that’s what I did to get my jdbc datasources up and running for both JBoss and Liberty.

In order to get it working on the Bluemix cloud, I had to choose to set the IBM specific binding files to use the resources according to Bluemix.

In IBM Bluemix, you can deploy applications in containers, VM’s as well as Liberty profiles on Cloudfoundry.

I user the latter approach. Then when you bind a ClearsDB MySQL, the name of the service will be bound to jdbc/servicename in the Liberty profile.

All information to connect is allready available and configured in that Liberty instance based on the bound service. You only need to bind your application resource reference to that specific resource.

That’s a Java EE app using a real datasource which is bound dynamically to your database as a service.

Write once, run anywhere?

Is it feasible to write enterprise applications in Java once while still being able to run them ‘anywhere’?

Yes, no, maybe, it depends…

The idea of the Java software development platform is based on this WODRA concept. Developers build an application using a standardized set of platform independent API’s and once the Java code is compiled to byte code it is the Java runtime environment that will make sure it runs everywhere.

In real life, it turns out to be very difficult to move applications from one environment to another. In the past I have worked on some of the replatforming projects.

Usually it involves different versions of the Java Runtime Environment, different versions of Java EE, different vendors of the former. As well as applications that have been build to use the bespoke features of the platform of choice. Something that isn’t necessarily a bad choice, but will make the effort of replatforming somewhat more difficult.

I have decided to create a Java EE 6 reference application. The goal of the reference application is to demonstrate that it is possible to create truly portable applications. Even at an advanced enterprise application level. But also to illustrate which design principles to take into account and to share my experiences in lessons learned about what to do and not to do for portability of applications.

I am allready confident that building a Java EE reference application will mean more work than building a solution for a target platform. However, I do beleive that it will help to determine best practices and design guidelines as well as insight in the portability and replatformability of Java EE enterprise applications.

I will use the following environments:

  • Windows, Linux CentOS, MacOS
  • Java JRE 6, Java JRE 7
  • Redhat JBOSS 7.1,  IBM WebSphere Liberty, IBM Bluemix
  • MySQL, Derby SQL databases (portability of JPA e.g.)
  • MongoDB (with and without application server support)
  • Java Security vs. OAUTH