CMake Java Support

At the end of last year I’ve worked on Dogtag PKI, which is enterprise-class open source Certificate Authority.

The project is written in serveral different laguages (C, C++ and Java), so I’ve used CMake as the new build system. I know CMake very well and use it since a long time. To be able to build the java project I needed Java support in CMake. The current support is broken and after talking to Bill Hoffman he suggested to write CMake functions. So I’ve started to write functions to compile java files, find jar files, bundle jar files and generate javadoc.

My Java support for CMake should provide everything you need to build java and jni projects. You find the files here:


Find JNI libraries and headers. I think this is the file from CMake itself.


Find all needed Java tools like javac, javadoc, jar, etc.


This file provides all needed function to support creating java projects in CMake. Most of the function are documented in detail. There is some documentation missing. I will try to add it soon.


This is needed to find the class files in the build directory. One .java file can create multiple .class files. So you have to glob for these file. There is support to only look for certain .class files.


This is a helper to create symlinks for versioned jar files.

To checkout the tree use:

git clone git://

It would be nice if this would be included into the CMake distribution, but at
the moment there is still documentation missing. I hope that this will help
some people to get their Java project built with CMake.

Comments, suggestions and patches are welcome!


This work is upstream and will be available with CMake 2.8.6 (September 2011).

You may also like...

4 Responses

  1. Mark says:

    Hello Andreas, thanks for posting this CMake Java stuff, it looks like it can be handy. I’ve just started trying it and found that, if it’s not already obvious to the CMake user, you need to have something like project(myProject Java) in your CMakeLists.txt or the variable CMAKE_Java_COMPILER used by add_jar will not be populated… even if FindJava has found your javac and populated JAVA_COMPILE.

  2. Alex says:

    There doesn’t appear to be a way of calling javah to generate headers from java files that declare native functions. Is this planned for a future release?

  3. It was to trivial calling it with custom_command. Patches are welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *