Alfred.app Glassfish workflow

alfred-iconI recently bought the Alfred.app Powerpack. It is byfar the best application launcher / automation engine I’ve ever used. One of the new features of the second version of this application is user customizable workflows.
In my daily activities, I start, stop, restart and kill my Glassfish server several times a day. In order to save me a few keystrokes and a few alt-tabbing, I created this small workflow allowing me to manage my local Glassfish instance.

You can find the Alfred worfklow at the following url http://bit.ly/alfred-glassfish.
You will probably need to adapt the GF_PATH variable in the script to point to the root of your Glassfish installation.

Once this small step is done, you’ll end up with the following prompt in your Alfred :

Alfred with Glassfish workflow enabled

Alfred with Glassfish workflow enabled

Continuous delivery using Maven / Shell

Continuous delivery


After Continuous Integration, this is the word we see on the web these days. Its meaning is really simple, it consists in reducing steps in application deployment. In order to do so a set of tools actually exists, you can use the same PaaS images (thanks to the newcomer Micro Cloud Foundry by VMWare or use a special amazon ec2 instance) to have a development environment similar to production one. And you can use Chef to manage and automate your configuration. While these alternatives are really interesting, I think they are way too powerful and difficult to setup in simple cases.
I will explain my “simple” solution based on maven, shell scripts and hostname detection.

Example release archive

An example is better than a thousand words, you will find an example of my solution in a github repository Easy Release Archive. It is a maven project building a zip artifact containing everything to be deployed, and an example script to setup the Glassfish server.

What is inside ?

To understand how it works, the best thing is to look what’s inside.

  • an assembly.xml file describing the files to include and their output name and location.
  • a few scripts in /src/main/resources
    • sanityCheck.sh : helper script sourcing the correct variables depending on the hostname of the machine and ensuring variables are correctly setup
    • setupGlassfish.sh : a sample script used to setup a Glassfish server with its required datasources and other parameters
    • a global folder containing global configuration files
    • a per hostname folder (in my case samva-mbp) containing a shell/envSetup.sh shell script to setup necessary variables and a config folder for special environment configuration files.
  • the pom.xml file describing artifact versions to use in the assembly and the lifecycle to use.

A simple mvn package will build the zip archive with everything described in the assembly.xml file. You will just have to unzip and run the script(s) corresponding to the application deployment for it to be done. You can add this command line to your build server and you will have a simple but powerful continuous delivery system !

ejb-client package + JRebel + Glassfish

JRebel ?

I use JRebel to speed up my development. It is a really impressive tool allowing to develop full blended Java EE application as you would develop in PHP. No redeploy, at the cost of a little slow-down in development mode. The tool does what it says, and it’s worth the price ! The JRebel plugin for maven does the job very well by generating the rebel.xml file that does the magic.

What’s the deal ?

Although JRebel is an awesome tool, there is some magic within, and, in special corner cases it might not work as expected. In my case I have a quite typical web application split in multiple parts:

  • a web application (war)
  • an ejb module (jar)
  • other modules not involved in my problem

The web application includes, in its WEB-INF/lib folder, the ejb-client artifact of my ejb module. To make it clear, ejb-client artifact is typically the jar containing the interfaces to be used by the client module(s).

The problem I had was that JRebel magic was reloading too much things : in fact, it reloaded classes even if they were not in the ejb-client. My application container (Glassfish 3.x) was not very keen on this thing. I opened a thread on ZeroTurnAround’s forum and the answer I got is that I have to find a way to ignore files in my ejb-client module. By digging in maven-ejb-plugin, I didn’t find anything to rename a file in the ejb-client module, and I didn’t find a parameter to pass to JRebel to specify which filenames can contain its configuration.
Continue reading

Glassfish 3.x – recover admin console access


I have an issue for quite  a long time with web administration console in Glassfish 3.x. When I try to access it, I point my browser to http://127.0.0.1:4848, the first access shows me the usual “Web console is loading stuff”, after a while, by looking at the log, I see the web administration is ready. I then hit refresh, it redirects me to
http://127.0.0.1:4848/common/index.jsf with a (not so) beautiful 404 error !

The discovery

I found the workaround by telling myself, wait, it never asked me to login….

Let’s try to hit http://127.0.0.1:4848/login.jsf, well, I got the usual login screen, I enter my login credential, and got redirected to http://127.0.0.1:4848/common/index.jsf…. but now it works ! (I tried looking at Glassfish sources to identify and narrow down the source of my problem, but with a quick lookup, I couldn’t figure out where the things are supposed to be done…)

The Useful tip !

To make it short, bookmark or be used to access the web administration console for your Glassfish 3.x server via http://127.0.0.1:4848/login.jsf !

Glassfish 3.x – Jersey with bundled dependencies

I just wanted to make a small post regarding an issue I spent almost a day getting rid off. I have a quite typical web architecture :

  • jar module encapsulating business logic (EJBs)
  • war module providing front end web access
  • war module for web service access (using JAX-RS)

The headache

Each war module depends on the ejb-client counterpart present in WEB-INF/lib. The problem I faced is that my @EJB injections was raising ClassNotFoundExceptions. I tried bypassing automatic injection with manual JNDI lookups but the same errors occurred. Playing with the debugger I found that the jars present in lib folder were not added into the web application’s classloader.

The workaround

I spent a lot of time trying many things to fix this and found out the trick by downloading Jersey’s sample. You simply have to have a sun-web.xml with the following content :


  

I hope it will help someone else!