views:

716

answers:

2

I really dislike PHP, but am pretty comfortable in Java. I have a stable Drupal installation that has been deployed to an Apache/Linux server. I don't know if the server currently supports Java. (What does it take to do that? I have programming in desktop apps for Java but never online before.)

For developing new modules for my site, is there any way that I can write Java and somehow have it work with the PHP?

+3  A: 

To use Java on a (web) server, you'll probably need:

  • an installed Java VM,
  • a servlet container or a full application server if you'll use some advanced techs like EJBs.

Theoretically you could run a web application without an installed servlet container, but that needs an embedded servlet container or some hacking, though. Most servlet containers or app servers can be used as frontend web servers, but if you decide to move them one step backwards behind the Apache httpd, then with the mod_jk connector plugin, you'll be able to load balance or proxy requests from the Apache web server to your servlet container (note, not just Tomcat: Glassfish and JBoss can be used as well) and hide the Java container from direct web access and provide an additional layer of security and load handling.

If somehow you'd like to run PHP and Java together, that is possible with some mild hacking: use Quercus (which is a Java implementation of the PHP language) on a suitable server (I'd prefer Glassfish v3), pack your app as a war file and you'll be able to run most PHP applications on a Java app server (and no, this doesn't mean any kind of sluggishness).

And, of course, if you push back the original Drupal application from the frontend Apache to a backend Java servlet container, then you'll be able to run Java and PHP apps side by side and the only job left for Apache is to load balance. If you are interested, check the Quercus and Drupal howto.

One more thing I forgot: if you'd like to create new Drupal plugins/modules in Java, that would only work with Quercus or if the Java and PHP apps are connected via web services or a cross-language framework like Protobuf or Thrift (so the view part could be Drupal plugin written in PHP, and business logic in Java running on a remote server). Note that I'm not an experienced Drupal plugin developer.

Tamás Mezei
Altough this answer is technically correct (I sure will try it myself just for the fun of it, thanks Tamás!), one cannot hate PHP so much as to actually write drupal modules this way. Even if it would be easier to incorporate java classes, writing drupal modules will still be easier in PHP.
EricSchaefer
Indeed :) It's just a straightforward solution to integrate mixed language apps (and Quercus can do suprisingly well on a well-suited server).
Tamás Mezei
+1  A: 

You're much better off simply biting the bullet and developing any custom modules in PHP. Even if you have to learn a good bit of PHP, it will be much much cleaner, more maintainable, and probably even quicker.

Mike Crittenden