Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing Apache Module using java

I see lot of examples on how to build a Apache Module using perl, C but there is no documentation to describe how to build a Apache Module using java.

Is it possible to build a Apache Module using Java?

like image 676
roronoa_zoro Avatar asked Oct 19 '22 00:10

roronoa_zoro


1 Answers

This is seldom practiced, because Apache often spawns multiple processes (cf. preforked) and running a Java Virtual Machine in each of them would inflate the RAM requirements to high heavens.

You can configure Apache to use only a single process, threaded. In this mode the arrangement makes more sense. But Apache installations like this are few and far in between.

Anyway, running a Java Apache module isn't much different from using Java in any other C code. You write a JNI-based wrapper around Apache functions in order to make them available to the Java code, you spawn the Java Virtual Machine, again with the help of JNI. JNI is your friend. There's a lot of documentation about it, a lot of books. Basically, you need to know how to write your own Apache module in C and you need to know the JNI and voila, you can build an Apache module in Java.

If you're looking for a library to do the JNI lifting for you, then this is off topic on Stackoverflow. And most library developers don't go there anyway because of the reasons outlined above. Here's an excerpt from one such undertaking: "The original plan for mod_gcj was to embed the libgcj runtime directly into the Apache processes, mucht like mod_perl does. Unfortunately, there was some clash between the traditional processing models with Java using threading and Apache using forking on Unix. As a result of this, mod_gcj is run in a a separate process that is forked from Apache and hosts its multithreaded libgcj runtime." - http://mod-gcj.sourceforge.net/about.html

like image 192
ArtemGr Avatar answered Oct 21 '22 04:10

ArtemGr