Recently I’ve been struggling to answer a simple question: “Does Windows Azure support Java?” In this blog post, I’ll explain why I don’t consider us as having Java support in Windows Azure today. Then I’ll show you a limited scenario (with a sample) in which you can run Java code in the cloud.
For some background, the question is coming up recently because Google just announced a preview of their Java support. For an answer about Java support across the entire Azure Services Platform, I recommend reading Mary Jo Foley’s recent article “What is Microsoft doing to add Java support to Azure?”
Windows Azure doesn’t support Java today
Most people asking the question of whether we support Java are asking because they have an existing investment in Java, and they’d like to run that in our cloud to get the benefits of Windows Azure. That existing investment is usually in the form of Java servlets, JSP, J2EE, etc., and is usually heavily tied to Tomcat, Jetty, or another web server technology.
The Windows Azure web role currently doesn’t support any of the popular ways of hosting Java servlets, so my first answer to the question is “No, Windows azure doesn’t support Java today.”
But, you can run whatever you want
Since MIX, when we announced .NET Full Trust and native code support, you can launch whatever code you want. If it can run on Windows without admin privilege and without install (copy-deploy only), it will probably work in Windows Azure.
It so happens that the Java Runtime Environment (JRE) can be copy-deployed, which means you can just invoke
java.exe. You could do this from a web role, but I would caution against using it as a way of responding to web requests, because starting a process on each web request is pretty inefficient. However, in the worker role, invoking an executable is perfectly reasonable.
The worker role in Windows Azure is a very simple pattern. You write a .NET assembly with a
Start method, which never returns. To run Java code instead, you just need to write a .NET assembly which invokes
java.exe from that
From that Java code, you can do whatever you want, but typically you’ll want to poll a Windows Azure queue and maybe write results back to storage. Because Windows Azure storage is based on HTTP and XML, it’s not too hard to write Java code to interact with storage.
In my next blog post, I’ll dive into a sample I wrote over the past few days called Shoutomatic that uses the technique described above. You can try it now at http://shout.cloudapp.net. It uses PHP to display a form and post user input to a Windows Azure queue. Java code running in my worker role than polls the queue, picks up incoming messages, and posts them to Twitter.
UPDATE: I’ve since posted the follow-up about Shoutomatic: “Programming Language Interoperability in Windows Azure”