Page tree
Skip to end of metadata
Go to start of metadata


mod_java is based on the swig wrapper used for mod_python so look there for any issues.

It's been tested with 1 call with Sun's Java 1.6 running the example script below and found to work.

NOTE: Sun JDK has a bug which causes freeswitch (among other Java programs) to crash immediately. To avoid problems, use an earlier release of 1.6 or any of the 1.5 JDK series.
NOTE: Also sending the -HUP signal to FreeSWITCH while mod_java is loaded will make FreeSWITCH exit due to the fact the JVM calls exit(); when it receives a HUP.



 Click here to expand Table of Contents

Building mod_java

Dependencies (gcj and classpath development tools)

You need a Java JDK, version 1.5 or greater, to build mod_java (and a JRE of the same version to use it). If ./configure doesn't detect Java, you'll have to pass the --with-java=/path/to/jni.h/directory flag. Something like the following:

Edit modules.conf.xml and uncomment languages/mod_java javac and jar have to be on your PATH during compilation. make installall

Enabling mod_java

Edit modules.conf.xml and uncomment:

Configuring mod_java

Edit java.conf.xml and fill in the path to your favourite Java 1.5 or greater virtual machine library.

The java.class.path parameter must contain freeswitch.jar and other paths are only necessary when you are not using JAR files, read on. You can create the freeswitch.jar file yourself by using jar command or any of your favorite tool. All the source files are there in <extracted-freeswitch-directory>/src/mod/languages/mod_java/src to build the required jar.

You can add any other options you like; for convenience remote debugging is enabled by default.

Building Java scripts

You need to have freeswitch.jar on your CLASSPATH when using javac.

Invoking mod_java applications

Use one of these in your dialplan:

The first will look for the given class on your CLASSPATH (set in java.conf.xml), the second will look in the given JAR file.


By default the remote debugger listens on port 8000 and IP The org.freeswitch.Launcher class in freeswitch.jar is used to launch scripts, so you can put breakpoints on it and from there trace into your code.

Example code


If you want to be aware of channel hang up then your java class should implement interface org.freeswitch.HangupHook. Method org.freeswitch.HangupHook.onHangup() is called not only when channel is being hanged up but also when it's being transferred. In this method you should shutdown you java-application

to release the given channel else general call processing will be blocked with your app.


Q: Does mod_java run in a single JVM or does it spawn a JVM per call?

A: There is a single in-process JVM, and each FreeSWITCH thread is attached to it before calling into Java (using the invocation API) and detached afterwards.