VTK 9 + Java on Mac

Just to add some info. I’ve been previously compiling VTK 9 RC 1 and 2 on Linux, and all went well. With 9.0 release I encountered two problems.

First, in addition to the usual Java_JAVAC_EXECUTABLE I needed also to set CMAKE_Java_COMPILER to point to javac. That was never the case before.

After that, VTK did build almost to completion: I didn’t get any JAR file, although the class files were compiled correctly. The problem seems to be the last stage of creating the JAR file - the jar program in the final “linking” command is empty. If you look at build/Wrapping/Java/CMakeFiles/vtkjava.dir/link.txt:

"" -cf ../../lib/java/vtk.jar -C CMakeFiles/vtkjava.dir .

If you substitute "" with jar after CMake is done with generation, then all works.

Yesterday I tried to compile on Windows. The standard Visual Studio generator failed to compile classes. The Ninja generator compiled the classes correctly, but - just as on Linux - failed in the final step of creating the JAR file. In the rules.ninja file I found the following:

rule Java_STATIC_LIBRARY_LINKER__vtkjava
  command = cmd.exe /C "$PRE_LINK && "" -cf $TARGET_FILE -C $OBJECT_DIR . && $POST_BUILD"

which looks exactly like the link.txt file on Linux. Now, I substituted "" with C:\PROGRA~1\Java\JDK18~1.0_2\bin\jar.exe in the above rule. After that VTK built correctly.